Cookie创建错误

时间:2013-01-31 12:43:29

标签: php wordpress

  

可能重复:
  Headers already sent by PHP

我在wordpress主题的主页上发现了错误的标题。我的功能喜欢;

function LoopCokiee() {
    if(isset($_COOKIE['PozCounter'])) 
    { 

         setcookie("PozCounter", ++$_COOKIE['PozCounter'], time()+3600); 
    } 
    else 
    { 

         setcookie("PozCounter", 1, time()+3600); 
    } 

    return $_COOKIE['PozCounter'];

}

function LoopCokieeUpdate () {
    $Kuki = $_COOKIE['PozCounter'];
    $Topl = '20'; //wp_count_posts()->publish;

    if ($Kuki > $Topl ) {
        setcookie("PozCounter", 1, time()+3600); 
    } else {
        return $_COOKIE['PozCounter'];
    }

}

这个功能完全适用于我的本地,但我知道 hostgator 的错误是什么?

当我打电话给我的功能时;

<?php 
 LoopCokiee();
 LoopCokieeUpdate();
echo '<!--LoopResults--'.LoopCokiee().'//'.LoopCokieeUpdate().'-->'
?>

这个错误apper;

Warning: Cannot modify header information - headers already sent by (output started at /home/igze/public_html/ddddd.com/wp-content/themes/smooth/home.php:1) in /home/igze/public_html/ddddd.com/wp-content/themes/smooth/PozHook/index.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/igze/public_html/ddddd.com/wp-content/themes/smooth/home.php:1) in /home/igze/public_html/ddddd.com/wp-content/themes/smooth/PozHook/index.php on line 11

我该怎么办?任何帮助谢谢。

2 个答案:

答案 0 :(得分:1)

发送标题之前

不使用任何输出

答案 1 :(得分:1)

在数据已经发送到Web浏览器输出后,您无法设置cookie。您必须在此之前设置Cookie或使用output buffering