Re: Weirdness with setcookie() (3rd time - come on people :)

From: Date: Tue, 14 Nov 2000 01:55:25 +0000
Subject: Re: Weirdness with setcookie() (3rd time - come on people :)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25088@lists.php.net to get a copy of this message
> > <?php > $hash = md5($username . $secret_word); > $values = array( > "username" => "test", > "permissions" => "AerFG", > "hash" => $hash > ); > setcookie("admin_cookie", serialize($values), time() + 12000000, > "/admin/", ".domain.com", 0); > header("Location: another_file.php"); > ?> > correct me if i'm wrong, but I think the location is your problem. the browser won't set the cookie until the header with the cookie information is sent to it. If you redirect the user to another_file.php it won't make a trip to the browser, in between the call to this file and another_file.php. So when you call another_file.php there is no cookie being sent to the browser. Does that make sense? What if you stored your cookie information in a session variable, then called setcookie() from another_file.php? Essentially storing the cookie information temporarily on the server until you were going to make the trip back to the browser and set the value in a cookie on the browser? I think that will solve your problem. Or you could just bypass cookies altogether, the far easier answer. Steve Nelson http://www.SecretAgents.com Tools for Fusebox Developers

« previous php.general (#25088) next »