Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Open a new window in new session (Solution Correct?)
    text
    copied!<p>Since i have not found any significant solution for open a new session for a new window/tab, i have thought for the follow solution that seems to work:</p> <p>1- created a like singleton Class 'SubSession'</p> <pre><code>&lt;?php /** * Provides a data structure and routines to be able to create and/or * activate a subSession * @author Roberto CASULA (casual4free@gmail.com) */ final class SubSession { private static $instance = NULL; private $current_active_name = 'MAIN'; private $SESSIONSTORE = array(); private $MAIN_SESSION; private function currentSessionStore() { $active_name = $this-&gt;current_active_name; $this-&gt;SESSIONSTORE[$active_name] = $_SESSION; } private function mainSessionStore() { $active_name = $this-&gt;current_active_name; if($active_name !== 'MAIN') throw new BadMethodCallException(__CLASS__.': the current active subSession is not MAIN'); $this-&gt;MAIN_SESSION = $_SESSION; } public function exists($name) { return array_key_exists($name, $this-&gt;SESSIONSTORE); } public function forkActive($name) { if( $this-&gt;exists($name) ) throw new InvalidArgumentException(__CLASS__.": $name yet exists"); $this-&gt;SESSIONSTORE[$name] = $_SESSION; } public function activate($name) { $active_name = $this-&gt;current_active_name; if($name === $active_name) return 'yet_active'; if($name == 'MAIN') : $this-&gt;currentSessionStore(); $_SESSION = $this-&gt;MAIN_SESSION; $this-&gt;current_active_name = $name; return TRUE; elseif( $this-&gt;exists($name) ) : $this-&gt;mainSessionStore(); $_SESSION = $this-&gt;SESSIONSTORE[$name]; $this-&gt;current_active_name = $name; return TRUE; else : throw new InvalidArgumentException('The searched name do not exists: '.$name); endif; } public function __get($name) { switch ($name) { case 'MAIN_SESSION' : if($this-&gt;current_active_name === 'MAIN') return $_SESSION; default : return $$name; } } private function __construct() {} public function __wakeup() {} public function __sleep() { return array('SESSIONSTORE'); } public function __destruct() { $this-&gt;activate('MAIN'); $_SESSION[__CLASS__] = serialize($this); } /** * * @return SubSession */ public static function getInstance() { if( self::$instance !== NULL) : return self::$instance; elseif( isset($_SESSION[__CLASS__]) ) : return self::$instance = unserialize($_SESSION[__CLASS__]); else : return self::$instance = new self(); endif; } } </code></pre> <p>2- added the follow line after "session_start();"</p> <pre><code>$__SUB_SESSION = SubSession::getInstance(); if( isset($_GET['sub_session_id']) ) { $subSessID = $_GET['sub_session_id']; if( !$__SUB_SESSION-&gt;exists($subSessID) ) $__SUB_SESSION-&gt;forkActive($subSessID); $__SUB_SESSION-&gt;activate($subSessID); } </code></pre> <p>3- created an entry in the .htaccess</p> <pre><code>RewriteRule ^@sub_session_id=([^/]+)(.*)$ $2?sub_session_id=$1 [QSA] </code></pre> <p>Now: <ol> <li>Since i'am serializing n copies of a <code>$_SESSION</code> array (in the <code>[SubSession-&gt;]$SESSIONSTORE</code> array) and <br/> knowing that <code>$_SESSION</code> array is serialized and unserialize using a different method,<br/> There could be some problems when i unserialize them ? <br/><br/></li> <li>Since i dont say in what order php calls the the <code>__destruct()</code> methods at the end of the script<br/> how can I be sure that this class will be the last destroyed? <br/> (this could prevent that some other self-serializing¹ will be stored on the 'MAIN' $_SESSION when a subsession² is active. </ol></p> <p>1: I use the words self-serialing to mean a class which serialize itself somewhere in the $_SESSION array before being destructed 2: I intend a subsession a session with the $_SESSION array copied from a position in the <code>[SubSession-&gt;]$SESSIONSTORE</code>, created by <code>$__SUB_SESSION-&gt;forkActive($subSessID);</code> and activated by <code>$__SUB_SESSION-&gt;activate($subSessID);</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload