Re: Re: YA Session Problem

From: Date: Fri, 03 Aug 2001 06:25:20 +0000
Subject: Re: Re: YA Session Problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-61086@lists.php.net to get a copy of this message
> --------- file 1 ----------- What filename is this?... > <? > > session_start(); > > if (!isset($var1)) { > session_register("var1"); > session_register("var2"); > header("location: index.php"); That should be Location with a capital 'L'. It matters. If you are using Cookies for sessions, then this page is sending both Cookie headers and Location headers in the same exchange, since you've got session_start() (and/or session_register()). You can't do that. Some browsers do the headers in reverse order, some do them in forward order, and thus there will always be some browsers that won't ever see the Cookies, since they did the Location first, so they never get the Cookie with the PHPSESSID in it, cuz they jumped off to index.php like you told them to in that Location header. Move the session_register("var1") and session_register("var2") to index.php, so that at least those will get done at some point. Whether the session_start() sets the first Cookie here and/or in index.php is not so important... Walk through it step-by-step and you'll see what I mean. Ooooooh. If this file *IS* index.php, you've got BIG logic problems... You are checking if $var1 is set, registering it, and then going back to index.php. Well, you may be registering it, but are you SETTING it to a value?... Now maybe session_register() will give it some value, just to register it... Or, maybe not. I sure wouldn't expect it to be SET just cuz I registered it. If you want to be *sure*, you'll need to set $var1 = 'something'; after the session_register("var1") and before the Location header... But you still have the whole Cookie/Location dichotomy problem. Basically, you *CANNOT* require a variable to be set on your homepage unless you expect every single person who ever links to your site to use: http://www.fromtheduke.com/session/index.php?var1=foo You might be able to get away with it if you do: header("Location: index.php?var1=foo&var2=bar"); That way, after they visit your page, you'll redirect with some GET vars to force them to have values... Not sure how useful that is in the Real World though... You may want to try to start doing a more realistic example of what you want to use Sessions for, because I think you've abstracted it to the point that you're trying to do something you'll never really need to do... -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#61086) next »