Cookies Not Set (setcookie)


If a script generates a php notice (which is logged, not displayed to
the screen) something gets output anyway; this output can prevent
setting cookies.
Quoted from bugs.php.net

This is nearly unbeliavable for me. I noticed that my PHP script cannot set cookies. The script was setting cookies good but… I keep developing the script and obviously somewhere in the development process, setcookie function has stopped working.

I tried everything. Everything was looking fine until I see the bug report which I quoted above…

It says, If you have an undefined variable in your script, it can prevent setting cookies in some cases. Which cases? Not sure. But in my case, this old bug report saved my time.

I checked my script. There was only one undefined variable. I declare it to NULL and that's all. setcookie function came back to life, started to set cookies without any problem.

So…

If you have some difficulties when you trying to set cookies, visit the links below and make yourself sure that you don't have any undefined variables in your script.

http://bugs.php.net/bug.php?id=21046
http://de.php.net/error_reporting
http://de.php.net/setcookie

Keywords:
PHP, setcookie, local, apache, remote, server, cookie, bug

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.