PHP Custom Session Handler Behavior -


i'm having trouble getting custom session handler work between different page requests. when session created handler works expected, when navigate page session cookie , session id remain same, session data deleted.

for example,

class nativesessionhandler implements \sessionhandlerinterface { protected $rootdir = '/tmp'; protected $savepath;  public function open($savepath, $name) {     $this->savepath = $this->rootdir . '/' . $savepath;     if (! is_dir($this->savepath)) {         mkdir($this->savepath);     }      return true; }  public function close() {     return true; }  public function read($sessionid) {     $file = $this->savepath . $sessionid;     if (file_exists($file)) {         file_get_contents($file);     }      return true; }  public function write($sessionid, $data) {     $file = $this->savepath . $sessionid;     return file_put_contents($file, $data); }  public function destroy($sessionid) {     $file = $this->savepath . $sessionid;     if (file_exists($file)) {         unlink($file);     }      return true; }  public function gc($maxlifetime) {     foreach (glob($this->savepath) $file) {         if (file_exists($file) && filemtime($file) + $maxlifetime < time()) {             unlink($file);         }     }      return true;     } }  // index.php $handler = new nativesessionhandler(); session_set_save_handler($handler);  session_start(); $_session['foo'] = 'bar'; echo session_id(); var_dump($_session); // 'foo' => 'bar'  // page.php $handler = new nativesessionhandler(); session_set_save_handler($handler); session_start(); echo session_id(); // same session id on index.php var_dump($_session); // returns null 

any figuring out how working appreciated!

apparently write or read methods of session handler don't work. try fix it. can set variable in $_session , use in same page because php uses session handler in end of script.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -