Sessions mixing up?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Sessions mixing up?

Post by xterra »

My site requires user to login. Say you log in as "John". Then you open up another window, and login as "Sarah". If you switch over to "John", now it's got Sarah's information! You can't gaurentee "John" will log out before Sarah uses it, so how do I keep them seperate?

Thanks very much.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

I guess you're using sessions. By default cookies are used to store session identifier...Put in other way per one domain a single identifier...
1. I suggest you don't allow people login with different user/pass and working simultanuously (if they want to....just will run two separate browsers)
2. If you still want to make it using different names at same tim...well you should change logic into storing user specific stuff in session, if you use $_SESSION['user_id'] That will perhaps be changed to $_SESSION['users']['id_1'] $_SESSION['users']['id_2'] etc etc...and have logic to trace per user basis ...but it is highly unlikely you want this behaviour.
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Post by xterra »

Thanks. I think I may have found a way around this. What do you think?

I made it so when you go to the site, if it detects session, it will go straight to user's control panel. If you want to go to another username, you must log out.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

See where you mixed it up :)
Basically this

Then you open up another window, and login as "Sarah"

should not happen...you should make simple check if user is already logged...this should be just redirect to control panel or whatever. Not showing the user/pass login form again.
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Post by xterra »

Thanks brother.
Post Reply