note 53147 rejected from function.setcookie by betz

From: Date: Sat, 11 Jun 2005 15:06:23 +0000
Subject: note 53147 rejected from function.setcookie by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-90268@lists.php.net to get a copy of this message
Note Submitter: dragos at popmedia.ro ---- I was under the impression that cookies wouldn't be set unless there was some content sent to the browser and that sending a cookie and then redirecting using header() would fail. Also, using header after any content was sent to the browser would also fail. Therefore, the following code wouldn't work: <? setcookie ('title', 'value', time()+60*60*24*365, '/'); header ('HTTP/1.0 302 Found'); header ("Location: http://www.example.com/"); ?> And it doesn't. However, neither should the following, as it sends content to the browser before sending headers: <? setcookie ('title', 'value', time()+60*60*24*365, '/'); echo ' '; header ('HTTP/1.0 302 Found'); header ("Location: http://www.example.com/"); ?> Yet it does work, without even a notice, in IE, Firefox and Opera, with PHP 5.0.3 and Apache 2.

« previous php.notes (#90268) next »