Store Mutiple Sessions Simultaneously?
Moderator: General Moderators
Store Mutiple Sessions Simultaneously?
Hi All,
I've run into an issue with sessions.
I create a session from a GET request like this:
$_SESSION['categoryID'] = $_GET['categoryID'];
What happens is that, when I open multiple browser windows/tabs from different categoryID's, the session variable gets overwritten with the newest value.
Sessions allow me to validate stuff at the beginning and all is good later.
I understand the concept of 1 session = 1 browser window/tab.
If I open a category where the categoryID=1 and then open multiple windows or tabs where categoryID=2 and categoryID=3 etc then, the $_SESSION variable is = 3.
Is there any possible way to tie the session to the newly opened browser window or tab. In this case, even if the user were to open new categories/windows, the older browser windows would still retain the session data.
I am looking for ideas on how to handle this issue when multiple windows are opened.
TIA
I've run into an issue with sessions.
I create a session from a GET request like this:
$_SESSION['categoryID'] = $_GET['categoryID'];
What happens is that, when I open multiple browser windows/tabs from different categoryID's, the session variable gets overwritten with the newest value.
Sessions allow me to validate stuff at the beginning and all is good later.
I understand the concept of 1 session = 1 browser window/tab.
If I open a category where the categoryID=1 and then open multiple windows or tabs where categoryID=2 and categoryID=3 etc then, the $_SESSION variable is = 3.
Is there any possible way to tie the session to the newly opened browser window or tab. In this case, even if the user were to open new categories/windows, the older browser windows would still retain the session data.
I am looking for ideas on how to handle this issue when multiple windows are opened.
TIA
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You could do something like this:
I would certainly think long and hard about the implications of doing that though. I am not sure this is a real problem. And, saying that a "redesign is not an option" is saying that good design is not an option.
Code: Select all
$browserID = md5($_SERVER['HTTP_USER_AGENT']);
$_SESSION[$browserID]['categoryID'] = $_GET['categoryID'];(#10850)
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
I understand your hesitance to add a GET variable to all your links. However, I'm not sure there's a choice. Yes you can create a random string for each session & make your $_SESSION variable a multi-dimensional array, but there's no way to pass that information between page loads without passing them via $_GET or $_POST. Normally of course you could use a session or cookie, but obviously that won't work.
Unfortunately I can't see any way other than passing a GET variable.
Unfortunately I can't see any way other than passing a GET variable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I'm curious to know how a $_SESSION multi-dimensional array would work. Are you saying I could pass the session_id through a GET statement? Could you please post an example on how to implement this..pickle wrote:Yes you can create a random string for each session & make your $_SESSION variable a multi-dimensional array, but there's no way to pass that information between page loads without passing them via $_GET or $_POST.
TIA
Each opened tab needs to maintain the session or the categoryID.arborint wrote:You could do something like this:I think I've missed something.. How would the HTTP_USER_AGENT differentiate a session when multiple tabs of different category IDs are opened?Code: Select all
$browserID = md5($_SERVER['HTTP_USER_AGENT']); $_SESSION[$browserID]['categoryID'] = $_GET['categoryID'];
These are the type of links that the user would open multiple browser windows/tabs.
.com/config.php?categoryID=1
.com/config.php?categoryID=2
.com/config.php?categoryID=3
.
.
.com/config.php?categoryID=20
The config.php has this bit of code:
$_SESSION['categoryID'] = $_GET['categoryID'];
TIA
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Sorry, I thought you wanted it for different browsers. I think I have the perfect to your unknowingly insane request! 
Code: Select all
//$_SESSION['categoryID'] = $_GET['categoryID'];(#10850)