PHP - Session Per Tab

PHP - Session per Tab

PHP stores session IDs in cookies and cookies are per client (browser), not tab. So there is no simple and easy way to do this. There are ways of doing this by creating your own session handlers, but they are more hacks than solutions and as such come with their own risks and complexity. For whatever reason you may need this, I am quite sure that there is a better architectural solution than session splitting.

How to have different sessions in different tabs

your approach is a little bit too complex for this task.

Instead of messing with variables, trying to store random stuff rewriting vars, you can just store nested arrays in session variables.

For example, on a page where user starts things out, do something like

$_SESSION['<random_string>']=array();

and then have the value of this random string stored in one of the 'hidden' input fields.

Whenever a form is submitted, or you need to do any kind of operation with session variables,do

if($_POST['action']=='Buy_bananas')
{
if(isset($_SESSION['<string>']))
{
buy($_SESSION['<string>']['bananas_to_buy']);
}
else
echo "Stop breaking code";
}

PHP: session_start() called 'simultaneously' in multiple tabs creates multiple sessions

The best solution I could come up with was to move the session "creation" (i.e., setting session variables) into the ajax.php file, executed only after a user has successfully sent their uname/pwd and so they are about to be redirected to a new page anyway (i.e., welcome.php). This means that login.php cannot be guaranteed to have access to any session variables set by ajax.php whatsoever, so it's just a dumb page that relies solely on its ajax calls to know what's going on. As it turns out, this isn't such a hassle after all.

How to detect if user open two tabs for same session?

1.The same problem (and solution) : https://sites.google.com/site/sarittechworld/track-client-windows

2.You can send information by POST or GET



Related Topics



Leave a reply



Submit