Page 1 of 1

How to force multiple sessions?

Posted: Thu Jul 30, 2009 10:56 am
by JeffG
I seem to have a fundamental misconception of how sessions work, although I have been coding with them apparently successfully until I found out something today.

At the start of each php script, I have the following:

Code: Select all

 
session_cache_limiter("nocache");
session_start();
 
$self    = $_SERVER['PHP_SELF']."?".SID;
 
Today, I wanted to test something on my local server, logging in as two different users. So I logged in with one user, opened a new tab (this is Firefox) and logged in as the other user. I expected to get two different sessions, but the second login used, and overwrote, the existing session file. Can I force separate sessions, or as I said at the start, am I labouring under a fundamental misconception?

(Incidentally, I got exactly the same thing when I ran two separate instances of Firefox.)

Re: How to force multiple sessions?

Posted: Thu Jul 30, 2009 11:03 am
by jackpf
Firefox uses the same cookies for all windows and tabs. There's no way to have two of the same cookie.

Re: How to force multiple sessions?

Posted: Thu Jul 30, 2009 11:08 am
by Eric!
You could use different session variables to "simulate" more sessions on the same browser if you need to. If the session exists, you could add a variable to expand it to a new session. I don't know why you would want to do that though....

Re: How to force multiple sessions?

Posted: Thu Jul 30, 2009 12:59 pm
by JeffG
OK, that explains something, thanks. It's a function of the browser, not the system it's running on. If I run one user in Firefox and the other in Internet Explorer, it works as I want it, but not both in the same browser. So that's all I need for local testing purposes.

I was a bit puzzled, because in the production system, several different computers are connecting to the server via an intranet, and it all works there.

Re: How to force multiple sessions?

Posted: Thu Jul 30, 2009 1:03 pm
by jackpf
That's because each computer will save their own cookies, unless they're configured to use the same cookie file/database.