I have a database based application that controls documents and each document has an id that I keep track of with a session variable. The question arises when I have several tabs open with different documents. The browser only keeps track of one session to the site, not a separate session id for each tab that is open. How do I get around this to allow multiple tabs to be open but to be able to distinguish which document is currently being worked on?
For example, if I make a menu selection to do something on the document it will change the current document id in any other tabs that are open. If that needs clarification let me know.
If a webpage has loaded a document from the server, you can simply store a hidden input field with the document. That way, when the next request is sent from the browser, it can send the value of that hidden field back to the server. Through the value of the hidden field, the server knows exactly which document is being worked on.
What if they select a menu item to go to another page where I would need to know the doc number there as well. Would you embed it in all the menu commands also?
Cookies are domain, path and and can be request specific. They can span a browser session or persist across browser sessions. They have nothing to do with the tabs or windows of a browser.
That’s what I thought. So I can’t use a cookie because it is akin to a session variable, i.e. shared between tabs.
I think I will go with a directed id number passed through htaccess for all requests. That way there is no crossover between tabs. Each tab will stand on its own.
Sure. The system is a quoting system. So a user can “create” a new quote document and then navigate the site to add products to the quote, add shipping and sales info, etc. So they may have several tabs open at once working on creating several different quotes. As they switch between tabs, the session will change in all the tabs to the quote in the last tab visited. That can cause some erroneous submissions if I don’t “tag” the quote id in each tab.
Up to this point, I have been using session variables for the quote id, price list, and other related information as well but that can be changed to retrieve the correct data for the quote (like price list) every time a submission is made if I populate the submission links with a quote id.
You will know what page you are on
so set the session
$mypage = $_SERVER[‘REQUEST_URI’]; // this contains the query string also, you may have to get the values from the $_GET values
$_SESSION[$mypage] = $myDocumentID;
Then on entering the page (tab)
Edit the document where $_SESSION[$mypage] == $mypage and you have the document id
I did not quite understand the question but why cannot you save many variables in one session. Use an array to store all the tabs and the documents in that array with additional configurations and settings. Session is the best way to handle live user data. Serialize the data if necessary.
Saving in hidden fields is also one good option. but use array so that you can manage the variables easily.