note 38984 added to function.setcookie
| From: | bdeguire at yahoo dot com | Date: | Wed, 14 Jan 2004 05:07:15 +0000 |
| Subject: | note 38984 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63489@lists.php.net to get a copy of this message | ||
I've lost many hours trying to make 'setcookie' work, so allow me to give you a
workaround that worked for me!
First of all, my situation:
In a login.php script, used to validate my users, I validate them through my DB, write a session ID
cookie using 'setcookie', then use a 'header("location: main.php")' to
go to the right location.
For some strange reason, my cookies were not saved on either IE 6 or Netscape 7! (I used a
'print_r ($_COOKIE)' on 'main.php' to verify my cookies.)
I noticed that if an output appeared *between* 'setcookie' and 'header', then
the cookie would be saved. (yes, this output would generate an error such as "header already
sent", but once this error corrected, a cookie would be saved)
So, my workaround consists in replacing the 'header("location: ...")' function
by these three lines:
print "<script>";
print "location.href='main.php';";
print "</script>";
And presto, my cookies worked!
----
Manual Page -- http://www.php.net/manual/en/function.setcookie.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38984
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38984&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38984&report=yes
Search -- http://master.php.net/manage/user-notes.php