I would hide in projects that you use $_SESSION . Projects should use just $_SESSION , as before, but you control what data is read. Also use your own SessionHandler so that when you destroy one project, $_SESSION will not have another.
You must include this file when the session starts. Then do not use session_start() anywhere.
class SessionAccess implements ArrayAccess { protected $handler; public $session; public function __construct (SharedSessionHandler $handler) { $this->handler = $handler; $this->session = $_SESSION; if (!isset($this->session[NULL])) $this->session[NULL] = []; } public function __get ($project) { return $this->session[$project]; } public function offsetGet ($id) { return $this->getKey($id)[$id]; } public function __set ($project, $val) { $this->session[$project] = $val; } public function offsetSet ($id, $val) { return $this->getKey($id)[$id] = $val; } public function __isset ($project) {
If you use this, you will have one large session for all of your projects. You do not need to change anything (other than deleting all session_start() ).
I believe that each of your projects is in its own way, so to distinguish between different $_SESSION s, use:
$sessionHandler->registerProject("projectName", __DIR__);
To access other sessions, use $_SESSION->projectName[$variable] .
Anything that is not in any registered directory will use the same global session repository. If any key is not installed in this global store, it takes the key from your local store - or a failure with a notification.
source share