Re: setcookie() not working - help!

From: Date: Thu, 28 Dec 2006 14:49:47 +0000
Subject: Re: setcookie() not working - help!
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-27333@lists.php.net to get a copy of this message
Beraru Liviu wrote:
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: <snip code>
From the PHP manual page for setcookie (shocking that it would have something useful for this problem isn't it!)... "setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE." Read the manual page: http://php.net/setcookie - everything you need is there. -Stut

« previous php.windows (#27333) next »