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:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
function get_global($key){
if(session_status()!=PHP_SESSION_ACTIVE)session_start();
$current_id=session_id();
session_write_close();
session_id(1);
session_start();
$value=null;
if(isset($_SESSION[$key]))$value=$_SESSION[$key];
session_write_close();
session_id($current_id);
session_start();
return $value;
}
function set_global($key,$value){
if(session_status()!=PHP_SESSION_ACTIVE)session_start();
$current_id=session_id();
session_write_close();
session_id(1);
session_start();
$_SESSION[$key]=$value;
session_write_close();
session_id($current_id);
session_start();
}
session_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();
$test=get_global("test");
if($test==null)$test=array();
$test=get_global("test");
$test[]="<span style='color:".$_SESSION['color']."'>Value: ".rand(0,100)." SessionID: $id</span><br>";
set_global("test",$test);
foreach($test as $t){
echo $t;
}
echo "<b>Reloads = ".$_SESSION['count'].", <span style='color:".$_SESSION['color']."'>This my color</span></b>";
exit;
?>