Handling sessions through different tabs with php

时间:2016-08-31 12:10:15

标签: php session

I need to have a session for each tab that is opened by the user. Some would say that this is impossible, because sessions are stored in cookies, and cookies don't recognize tabs and all that.

But there was a comment made on the PHP manual that made me think maybe it was possible, i'm just not sure how to do the second part. But let's start from the beginning.

So, the idea is having different Session_names based on a unique ID, then passing all that through the URL. So it is something like this:

if(!preg_match('/^SESS[0-9]+$/',$_REQUEST['SESSION_NAME'])) { 
                        $_REQUEST['SESSION_NAME']='SESS'.uniqid(''); 
                    } 
                output_add_rewrite_var('SESSION_NAME',$_REQUEST['SESSION_NAME']); 
                session_name($_REQUEST['SESSION_NAME']);

So, so far so good, i am generating the unique ID. The problem is, how do i pass this ID onto my tabs? through the URL? Even so, how would i go about inserting it into my URL? The commenter specified something like this:

< ?php 
header('location: script.php?'.session_name().'='.session_id() 
      . '&SESSION_NAME='.session_name()); 
?> 

<input type="image" src="button.gif" onClick="javascript:open_popup('script.php?<?php 
echo session_name(); ?>=<?php echo session_id(); ?>&SESSION_NAME=<?php echo session_name(); ?>')" />

But i'm not sure how to implement this onto my own website. I need to pass it onto this page (that i'm opening through js)

document.getElementById("details").action = "../details.php?tipo=" + tipo + "&periodo=" + periodo;

So how do i add the session information to this URL?

0 个答案:

没有答案