Re: Weirdness with setcookie() (2nd time)

From: Date: Tue, 14 Nov 2000 22:02:07 +0000
Subject: Re: Weirdness with setcookie() (2nd time)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25281@lists.php.net to get a copy of this message
> <?php > $lifetime = time() + 12000000; > $encriptado = array( > "username" => $strUsername, > "permissoes" => $myrow["permissoes"], > "hash" => md5($strUsername . $segredo) > ); > echo "<pre>\n"; > print_r($encriptado); > echo "</pre>\n"; > $valor = serialize($encriptado); > setcookie("musica_admin", $valor); > include("admin.php"); > ?> > > The array named $encriptado has stuff inside it, since print_r() prints > the whole structure with no problems. I already tried setting the expire > time to a really big number, and already tried setting both the path > parameter and the domain parameter (With the 2 dots ".domain.com"). > > Nothing like this mattered, as the cookie keeps being empty. I already > tried using header("Location: admin.php"); by the way and nothing. > > This is the way it was supposed to work: > > index.php -> file with the login form. > login.php -> file with the whole login checking, it creates the cookie > admin.php -> frameset with 2 scripts that then checks for the cookie > > So, index.php calls login.php for the login checking, going to the > database and stuff, and if everything is okay, it redirects or includes > the admin.php file. > > The cookie is always empty no matter what. This exact same code used to > work perfectly for PHP3. Actually the same exact code work in a Solaris > box running PHP4.0.3pl1. > > Another hint, this same site has another section that uses cookies and in > that section the cookie _does_ get set correctly. Only on this back-end > interface is that the problem happens. > > If anybody has any ideas on this issue, it would help a lot as I'm getting > crazy here :) Maybe your old machine had output buffering turned on in php.ini, and the new one doesn't. If so, your problem is the print statements *before* the SetCookie. You cannot send anything to the browser before a cookie. See my Tip about headers and cookies on http://zend.com for a more detailed explanation.

« previous php.general (#25281) next »