In php how to handle different sessions in same browser?
5 Answers
You could possibly look into session_name(), and retrieve sessions based on a name parameter. But I don't see anything that you can't handle using a single session; even perhaps having an Administrator user log in as a Regular user to act as that user.
Cookies or set session_id() before session_start() but the later is not recomended , use cookies instead of session if you need multiple sessions in the same browser .
-
Cookies are sent and retreived within the session, so this is not a solution. Commented Dec 22, 2010 at 7:58
-
but you can set different cookies for diferent things within the same session ( witch in turn may act like multiple sessions if you use $_COOKIE instead of $_SESSION ) , or as i told you can set a session_id for a given request witch in turn ( i suppose ) will overwright you're cookie PHPSESSID so the php app whont know witch session id to set for witch request , so the only thing you can do is trick the app to "think" it's using multiple sessions for the same PHPSESSID cookie . Commented Dec 22, 2010 at 8:07
Use the session id in the url and use set_session_id()
to set it at the start of each request.
The disadvantage is that a session may be restored in a new browser session because the url with id can be reopened in a new browser instance or even a different browser.
But why would you need to do this?
-
this will work for development , but in production you can't ask you're users to use this FF extension , plus what about users that use Safari or IE ? Commented Dec 22, 2010 at 8:10
You could use a querystring with a unique ID which you set during login, and use that to find the session variable you need.
Another easy trick if you need multiple sessions just for yourself is to use subdomains (www1.url.com, www2.url.com) as session information is stored for each unique domain.