<?php
$c_file="shu.txt";
if(!file_exists($c_file)){
$myfile=fopen($c_file,"w");
fwrite($myfile,"0");
fclose($myfile);
}
$t_num=file($c_file);
if($_COOKIE["date"]!="date(Y年m月d日)"){
$t_num[0]++;
$myfile=fopen($c_file,"w");
fwrite($myfile,$t_num[0]);
fclose($myfile);
setcookie("date","date(Y年m月d日)",time()+60*60*24);
}
$myfile=fopen($c_file,"r");
echo $myfile;
fclose($myfile);
?>
总是报setcookie("date","date(Y年m月d日)",time()+60*60*24);这一行出错,检查多时了,还是没有发现问题

解决方案 »

  1.   

    重新修正代码,还是有问题:
    <?php
    $c_file="shu.txt";
    if(!file_exists($c_file)){
    $myfile=fopen($c_file,"w");
    fwrite($myfile,"0");
    fclose($myfile);
    }
    $t_num=file($c_file);
    if($_COOKIE["date"]!="date(Y年m月d日)"){
    $t_num[0]++;
    $myfile=fopen($c_file,"w");
    fwrite($myfile,$t_num[0]);
    fclose($myfile);
    setcookie("date","date(Y年m月d日)",time()+60*60*12);
    }
    $myfile=fopen($c_file,"r");
    while(!feof($myfile)){
    $num=fgetc($myfile);
    if($num){
    echo $num;
    }
    }
    fclose($myfile);
    ?>
      

  2.   

    Warning: Cannot modify header information - headers already sent by (output started at D:\APMW\www\index.php:6) in D:\APMW\www\index.php on line 240

    这是报错信息
      

  3.   

    这里报的240处就是这里setcookie("date","date(Y年m月d日)",time()+60*60*12);
      

  4.   

    在你調用setcookie之前已經有東西輸出來了檢查一下文件是不是已經輸出了空格,換行之類的東西
    還有,你的文件是不是UTF-8編碼的,是不是文件開頭帶著BOM
      

  5.   

    发现在当前页面测试没有问题,一使用require调用这个页面时就会报错。我用的是GB2312
      

  6.   

    应该是 bom的问题吧 
    欢迎访问:http://shop60925320.taobao.com?asker=csdn 我新开的店铺
      

  7.   

    你調用它的文件們在調用它之前一定有輸出...<?php
    if (headers_sent($filename, $linenum)) {exit"Headers already sent in $filename on line $linenum" .}?>
    把這個語句放在setcookie之前.可以幫你定位
      

  8.   

    <?php
    if (headers_sent($filename, $linenum)) {exit("Headers already sent in $filename on line $linenum");}?> exit忘了加上括號...