> --------- 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

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

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:


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

WARNING [EMAIL PROTECTED] address is an endangered species -- Use
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

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to