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
Convert Hex to Ascii Characters
Why Doesn't PHP Dom Include Slash on Self Closing Tags
How to Integrate PHPmailer with Codeigniter 3
How to Add a View Helper Directory (Zend Framework)
Given an Email as Raw Text, How to Send It Using PHP
PHP - Syntax Error, Unexpected T_Constant_Encapsed_String
Reply-To Address in PHP Contact Form
Create a Insert... Select Statement in Laravel
Maximum Length of Generated Hash When Using Password_Hash
Dynamically Bind MySQLi_Stmt Parameters and Then Bind Result (Php)
Best Way to Check a Empty Array
Mysql: Determine Table's Primary Key Dynamically
Pass Form Data to Another Page with PHP