setcookie then redirect

From: Date: Wed, 10 Jul 2002 23:34:43 +0000
Subject: setcookie then redirect
Groups: php.general 
Request: Send a blank email to php-general+get-106978@lists.php.net to get a copy of this message
List, I'm trying to set a cookie like this: <?php function redirect() { if ($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']) {
	    $to = func_get_arg(0);
	    header("HTTP/1.1 301\n");
	    header("Location:http://".$_SERVER['SERVER_NAME'].$to."\n");
	    header("Set-Cookie: sid=$sid;\n\n");
	    exit();
} } function login() { [... validation code here ...] // set my cookie setcookie("sid", $sid); return true; } if (login($token) == true) { redirect("/somepage.php"); } ?> but this thing isn't working...seems like it's not writing the SID value in the cookie. In other code (on /somepage.php for example) when I read the cookie value ($_COOKIES['sid']) it can't find it. Ideas? So how do I set cookies then redirect? I'm using Apache 1.3.x, PHP 4.1.2, RH7.3 TIA /B

« previous php.general (#106978) next »