Two application using the same session variables

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
yueliu_32214
Forum Newbie
Posts: 2
Joined: Wed Apr 19, 2006 3:38 pm

Two application using the same session variables

Post by yueliu_32214 »

I have two totally different applications. They are all using session variables to authenticate users. When a user visit these two applications at the same time, if he logs out in one application, he will also be logged out automatically for the other one. Since the application's logout php script is:

session_start();
session_destroy();
$_SESSION=array();

So, logging out in one application will actually destory all the session variable. Also, if they both authenticate a user based on checking session variable session['username'], when you login in one application, you actually logged in both.

How can I make this work?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You can't. If you destroy the session how do you expect it to be available in the other application?
yueliu_32214
Forum Newbie
Posts: 2
Joined: Wed Apr 19, 2006 3:38 pm

Post by yueliu_32214 »

So, How can I logout one wihout affecting the other one in the same browser?
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post by ed209 »

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Just namespace the data in the session:

Code: Select all

$_SESSION['app1']['username']
$_SESSION['app2']['username']
(#10850)
Post Reply