Forum Moderators: coopster
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 from different categoryID's, the session variable gets overwritten with the newest value.
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 have the session variable remain the same and not update itself everytime a new window is opened?
How do I modify this?
TIA
Thanks, but that does not work.
What happens is, the user opens multiple browser windows or tabs. Hence, categoryID=1,categoryID=2, categoryID=3 etc. Each of these needs to be saved as a unique session.
The session variable would need to be overwritten and each of the newly opened categoryID instance needs to be saved as a session. The previously opened browser windows need to preserve the same categoryID though.
Any ideas?
TIA
Instead of storing sessions as a flat value, I would use array. So something like:
if(isset($_SESSION['categoryID']))
{
$_SESSION['categoryID'] = $_GET['categoryID'];
}
else
{
$_SESSION['categoryID'] = array($_GET['categoryID']);
}
So if you need to access the categories visited you can do this:
$_SESSION['categoryID'][0], $_SESSION['categoryID'][1], where 0 and 1 is the index :).
Yes, could you please point me in the direction on how to maintain the one user, multiple browser feature.
To recap, these are the list of links that the user would open multiple browser window links with. Note that, the GET request is just a categoryID, nothing else to it.
.com/config.php?categoryID=1
.com/config.php?categoryID=2
.com/config.php?categoryID=3
.
.
.com/config.php?categoryID=20
[edited by: HoboTraveler at 5:22 am (utc) on Aug. 13, 2007]
If you want to stick to the SESSION solution, every session name need to be unique, and just the way it is I don't see a quick solution.
Or try the SESSION array solution given above.
this is really a logic problem more than anything else.
What functionality are you trying to acheive?
does it have to do with tracking?
I generate a list of twenty categories.
The URLS are like these:
.com/config.php?categoryID=1
.com/config.php?categoryID=2
.com/config.php?categoryID=3
.
.
.com/config.php?categoryID=20
Each category has unique forms.
When the user clicks on a category, the category ID is stored in a session variable. Session variables are a must because the ID's are reused across multiple forms in the same category.
The session variables begin to create an issue when multiple tabs/browser windows are opened.
My goal is to allow users to open multiple tabs and allow them to work on multiple categories simultaneously.This is why I need the session variables to store the category ID's uniquely and not have them overwritten.
Ideas welcome..
well you are going against the session logic and how browsers hadnle it, you need to change you logic, as Habtom mentioned, just maintain it in the url or find a way to store multiple id's in the session and be able to figure out which to use where
What is behind storing it in a SESSION variable?
Well, each category has atleast 20 forms. Each form has to go through multiple submit levels. Its not easy as just a POST.
I also need to pull data out associated with the ID and store the vars in session vars.
Also, initially, I validate the GET variable ID and if true store it in a session var. This prevents me from resending all those GET vars in every request. And if I did use GET vars, I'd have to validate them at every step and initialize a lot of variables.
Sessions allow me to validate stuff at the beginning and all is good later.
This works great. But not so great when multiple windows/tabs are opened.
I understand the concept of 1 session = 1 browser window/tab.
I am looking for ideas on how to handle this issue when multiple windows are opened.
One option is not to overwrite the session vars if they have been initialized already. However, the user does need to select a new category by going back home. So a category session ID would need overwritten anyway.
I guess this leaves us with one option. 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.
How feasible would this be? Is it possible to tie a session and make it unique maybe to the PID or browser tab?
Would this be possible with cookies? Can cookies be associated to individual browser windows/tabs?
Ideas welcome..
TIA
I tried to get you a solution for that, it seems there won't be away around it. May be somebody else will give you a hint.
Well, each category has atleast 20 forms. Each form has to go through multiple submit levels. Its not easy as just a POST.
If it is that long, perhaps they should stick to one of the categories.
Habtom
$threadID = something;
$_SESSION[$threadID] = array();
As Habtom mentioned, you carry the threadID in the URL, or in a hidden form element across your steps (just like PHP does with sessionID when cookies are turned off), and when you want to save some data you save it in the appropriate array element, e.g.
$threadID = $_REQUEST['threadID'];
$_SESSION[$threadID]['value1'] = $_POST['value1'];
$_SESSION[$threadID]['value2'] = $_POST['value2'];
etc.
The threadID can be the same as your categoryID to keep it simple, or you can get more fancy and allow multiple tabs for the same category by setting the threadID to the current timestamp when the user starts a new category.
That a user leaves a form half filled and moves to fill another makes no sense to me . I would simply alert them with javascript to complete the curent form before cliking on another.
If each of your forms spans over multiple pages,the session will likely expire anyways by the time they are filling more than one simultlaneously(assuming the volatile 24 minutes expiry default)
yes,it can be done the way you want it somehow,but may be you should not.
You will have to modify every link,form action,and even javascript,img src,iframe,would you want that additional load?
There's a thread in [php.net...] about that.Hope it'll inspire you somehow.
Good luck!
Thank-You all for turning in your ideas..
I ended up implementing multi-dimensional arrays and am able to call session arrays based on the category called. Individual tabs or browser windows do not mangle the session vars now..
Works great!
Thanks
[edited by: HoboTraveler at 10:39 am (utc) on Aug. 23, 2007]