Get a shared session.
Sometimes is good can interchange messages and vars between one session and another, but PHP dont support this. I create this script that allows with session_id() change from current session to shared session (this is, info with scope to all sessions) for read and write info and back in to user session. The code:
ini_set('display_errors',1);error_reporting(E_ALL);
functionget_global($key){//Get current sessionif(session_status()!=PHP_SESSION_ACTIVE)session_start();$current_id=session_id();session_write_close();//Set a global session with session_id=1session_id(1);session_start();//Get superglobal value$value=null;
if(isset($_SESSION[$key]))$value=$_SESSION[$key];session_write_close();//Set the before sessionsession_id($current_id);session_start();
return$value;
}
functionset_global($key,$value){//Get current sessionif(session_status()!=PHP_SESSION_ACTIVE)session_start();$current_id=session_id();session_write_close();//Set a global session with session_id=1session_id(1);session_start();//Set superglobal value$_SESSION[$key]=$value;session_write_close();//Set the before sessionsession_id($current_id);session_start();
}//Example
//Begin my session normallysession_start();
if(empty($_SESSION['count'])){$_SESSION['count']=0;$_SESSION['color']="rgb(".rand(0,255).",".rand(0,255).",".rand(0,255).")";
}$_SESSION['count']++;$id=session_id();//Get the superglobal$test=get_global("test");//Set the superglobal test with empty array if this dont setif($test==null)$test=array();//Get the superglobal$test=get_global("test");//Set values for each reload page and save the session_id that create it$test[]="Value: ".rand(0,100)." SessionID:$id
";//Save the superglobalset_global("test",$test);//Show the superglobalforeach($testas$t){
echo$t;
}
echo"Reloads = ".$_SESSION['count'].", This my color";
exit;?>