note 38984 rejected from function.setcookie by betz

From: Date: Wed, 14 Jan 2004 11:20:47 +0000
Subject: note 38984 rejected from function.setcookie by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63507@lists.php.net to get a copy of this message
Note Submitter: bdeguire@yahoo.com ---- 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!

« previous php.notes (#63507) next »