I created a class that will handle the session_set_save_handler but after executing session_start i will get server error this is my code,
<?php
defined('protect')||(header("HTTP/1.0 404 Not Found"));
require_once INCLUDES . '/query.php';
class MySQL_Session{
private $dbConnect = null;
protected $savePath;
protected $sessionName;
private $sessionTable;
private $sessionColumn;
public function __construct() {
$c = new Configuration();
$this->sessionTable = $c->sessionTable;
$this->sessionColumn = $c->sessionColumn;
session_set_save_handler(
array($this, "mysql_session_open"),
array($this, "mysql_session_close"),
array($this, "mysql_session_select"),
array($this, "mysql_session_write"),
array($this, "mysql_session_destroy"),
array($this, "mysql_session_garbage_collect")
);
register_shutdown_function('session_write_close');
}
public function mysql_session_open($session_path, $session_name) {
$this->dbConnect = new DatabaseConnection();
$this->savePath=$session_path;
$this->sessionName=$session_name;
return TRUE;
}
public function mysql_session_close() {
return TRUE;
}
public function mysql_session_select($SID) {
$insert = new DatabaseQuery();
$query = "SELECT value FROM sessioninfo
WHERE SID = '$SID' AND
expiration > ". time();
$insert->select($query);
if (num_rows()) {
$row=mysql_fetch_assoc($insert->result);
$value = $row['value'];
return $value;
} else {
return "";
}
}
public function mysql_session_write($SID, $value) {
$lifetime = get_cfg_var("session.gc_maxlifetime");
$expiration = time() + $lifetime;
$query = new DatabaseQuery();
$result = $query->insert($this->sessionTable, implode(',',(array)@$this->sessionColumn), implode(',', array($SID,$expiration,$value)));
if (!$result) {
$field = array($this->sessionColumn['i'], $this->sessionColumn['e']);
$value = array($SID, time());
$operator = array('=','>');
$query->where = string::MySQL_Where_Clause((array)$field,(array)$value,(array)$operator,array('OR'));
$query->update($this->sessionTable, implode(',', array($this->sessionColumn['e'], $this->sessionColumn['v'])), implode(',', array($expiration,$value)));
}
}
public function mysql_session_destroy($SID) {
$delete = new DatabaseQuery();
$delete->where = string::MySQL_Update_Setter($this->sessionColumn['i'],$SID);
$delete->delete($this->sessionTable);
}
public function mysql_session_garbage_collect($lifetime) {
$delete = new DatabaseQuery();
$delete->where = string::MySQL_Update_Setter($this->sessionColumn['e'], time() - $lifetime,'<');
return $delete->delete($this->sessionTable);
}
}
?>
then i will try to execute like this
<?php
defined('protect')||(header("HTTP/1.0 404 Not Found"));
class template{
function render(){
include INCLUDES.'/session.php';
$session = new MySQL_Session();
session_start();
$_SESSION['adminToken']='test';
}
}
?>
but i will get an error on session_start() but if i will try to remove the session_start() the code will run smoothly please help me about this
i will appreciate for any help