note 56172 deleted from function.session-set-save-handler by drak

From: Date: Sun, 11 Mar 2012 04:32:31 +0000
Subject: note 56172 deleted from function.session-set-save-handler by drak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186593@lists.php.net to get a copy of this message
Note Submitter: kevin at insuremytrip dot com ---- When creating a session-handling class, I have discovered that it is important to remember that your session object and the $_SESSION global are TWO SEPARATE ENTITIES. You need to create a reference between your Session Object and the built-in $_SESSION global: <?php session_set_save_handler( array(&$this, "_OPEN"), array(&$this, "_CLOSE"), array(&$this, "_READ"), array(&$this, "_WRITE"), array(&$this, "_DESTROY"), array(&$this, "_GC") ); session_start(); header("Cache-control: private"); // to overcome/fix a bug in IE 6.x $this->session =& $_SESSION; ?> Additionally, when you add a $_SESSION variable, it's a good idea to add it as a Session Object variable at the same time, if you want your code to use the Session Object between page changes/reloads: <?php function setSessionVariable($key,$value) { $_SESSION[$key] = $value; $this->session[$key] = $value; return; } ?>

« previous php.notes (#186593) next »