Page 1 of 1

Session is getting overwritten in php using same browser.

Posted: Sun Jan 10, 2010 3:24 am
by Sankalp_nyn
In having a problem of session overwriting using one browser.

Using PHP:

After a successful login I register the user session as below:
$_SESSION['username'] =$username;

I call this session from other pages for users ($_SESSION['username']) to get relevant data for the user.

It works fine when accessed with one user logged in. The problem starts when second user logs in.. Now, when I refresh the page of first user, second user data appears.. as session $SESSION[username] is overwritten by second logged in user.


This happens only when using same browsers for the users, this problem does not occur if both logged in different browsers. (Eg: if users both using firefox having problem, if one uses firefox and other uses Opera the problem does not occur.

Please.. Please give me some advice on this...

Re: Session is getting overwritten in php using same browser.

Posted: Sun Jan 10, 2010 3:40 am
by kaisellgren
Are you saying that you are trying to log in with different accounts on your own?

Re: Session is getting overwritten in php using same browser.

Posted: Mon Jan 11, 2010 10:22 am
by vanguard
Are you trying to log in with both accounts from the same computer? If so, this would be perfectly normal behaviour. If this isnt the problem, check to see where your sessions are being stored (session.save_path) and whether you are manually setting a session name with session_name. I wouldnt have thought these would be a problem, but theres no harm in checking.

- Alex

Re: Session is getting overwritten in php using same browser.

Posted: Mon Jan 11, 2010 1:16 pm
by AbraCadaver
AFAIK, you can't have two separate sessions at the same time using one browser. The browser stores a cookie with the session id and that single cookie would be used by all browser instances.

Re: Session is getting overwritten in php using same browser.

Posted: Mon Jan 11, 2010 4:49 pm
by vanguard
However, it would be possible to emulate having multiple sessions if you design the site to do that, using arrays in the session. Its just not very useful.