setcookie() not working - help!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
  I am a newbie in php and have a problem with setting up a cookie.
  The code should just verify if the user's browser has a cookie from my site, and if there is one, then increase the counter file. If not, then the counter should not be increased.
   
  I have Xampp installed, the latest version, which means also php 5.
  But, when I test the script I get from the my server the following error message:
   
  Warning: Cannot modify header information - headers already sent by (output started at C:\Programme\xampp\htdocs\Laborator\index.php:5) in C:\Programme\xampp\htdocs\Laborator\index.php on line 55
   
  Line 55 is where stands the setcookie() method.
  I have no idea what is wrong and what this error message means.
   
  Could someone please help me?
   
  The code I wrote is this one:
   
   
  <?
$file="counter.txt";     
if (!file_exists($file)){
$ix=fopen($file, "w");
fwrite($ix, "0");
fclose($ix);
}
  $ix=fopen($file, "r");
$counter=fread($ix, 10);
fclose($ix);
  $cookie = $_COOKIE['cookie'];
     
if(!isset($cookie)){
                       //FOLLOWS LINE 55:
setcookie ("cookie" , "ok");
$counter++;
$ix=fopen($file, "w");
fwrite($ix, $counter);
fclose($ix);
}
     
$lung=strlen($counter);
$counter_grafic="";
for ($pos=0; $pos<$lung; $pos++){
$cifra=substr($counter, $pos, 1);
$counter_grafic.="<img src=\"img/cifre/$cifra.jpg\">";
}
?>
   
  Liviu Beraru

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux