faqts : Computers : Programming : Languages : PHP : Not Quite PHP : HTTP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 22 people (73%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Why aren't my cookies set when I follow setcookie() with a redirect?

Jul 11th, 1999 05:57
Nathan Wallace, Leon Atkinson,


Many browsers do not support setting cookies and doing a redirect in 
the same request.  For full information abotu this problem, search the
Microsoft knowledge base for Q176113 or see:
    http://support.microsoft.com/support/kb/articles/q176/1/13.asp
If you do these things via JavaScript it does work though:
  echo '<SCRIPT LANGUAGE="JavaScript">';
  echo "   document.cookie = 'Authenticated=1'; ";
  echo "    location.href=\"service.php3?RowId=$RowId\"";
  echo " </SCRIPT>";
This will set the cooke Authenticated to 1, and redirect to the
service.php3 url.
Alternatively, you can just insert a META tag that refreshes and
redirects after 0 seconds. Get's around the problem nicely :)