Below is copied directly from the php manual, I'm not sure how to set this up, there are just two things I need to do..
- write some code when the session is destroyed
- set the session_cache_expire to 20 mins - do that in the class or as a separate call?
Do I need to run sessionsavehandler() for every instance, every time I have session_start on the page? If someone could please outline the steps I need to take to use this class that would be great.
<?php
new SessionSaveHandler();
?>
<?php
class SessionSaveHandler {
protected $savePath;
protected $sessionName;
public function __construct() {
session_set_save_handler(
array($this, "open"),
array($this, "close"),
array($this, "read"),
array($this, "write"),
array($this, "destroy"),
array($this, "gc")
);
}
public function open($savePath, $sessionName) {
$this->savePath = $savePath;
$this->sessionName = $sessionName;
return true;
}
public function close() {
// your code if any
return true;
}
public function read($id) {
// your code
}
public function write($id, $data) {
// your code
}
public function destroy($id) {
// your code
}
public function gc($maxlifetime) {
// your code
}
}
new SessionSaveHandler();
?>