我正在尝试设置自定义会话处理程序(请参见下面的代码),但是我一直收到错误消息(http://php7test.com/alp-ing/)。有什么建议么?
我得到的错误: 警告:未知:无法使用用户定义的保存处理程序写入会话数据。 (session.save_path:/ var / lib / php / sessions),位于第0行的“未知”中
public function open ($savepath, $cookiekey) {
// $this->fw_session_log('info', 'open');
$this->gc(18800);
return true;
}
public function close() {
// $this->fw_session_log('info', 'close');
return true;
}
public function read ($id) {
$database = $this-> database();
if (!$database) return "";
// $this->fw_session_log('info', 'read');
// TRUE
if (!preg_match('/^([0-9a-z]{32,52})$/i', $id)) return "";
#if (! $res = $database->GetResult('SELECT * FROM '.$this->dbsessiontable.' WHERE sessionid=\''.$id.'\' AND ip=\''.$_SERVER['REMOTE_ADDR'].'\'')) { return false; }
if (!$res = $database->GetResult('SELECT * FROM ' . $this->dbsessiontable . ' WHERE sessionid=\'' . $id . '\'')) {
return "";
}
$sessiondata = $database->FetchArray($res);
if (is_null($sessiondata)) {
return "";
} else {
$this->lastaccess = $sessiondata['lastaccess'];
return base64_decode($sessiondata['value']);
}
}
public function write ($id, $data) {
$database = $this-> database();
if (!$database) return false;
//$this->fw_session_log('info', 'write');
if (!preg_match('/^([0-9a-z]{32,52})$/i', $id)) return false;
$data = base64_encode($data);
$database->GetResult('UPDATE ' . $this->dbsessiontable . ' SET value=\'' . $database->escapeString($data) . '\', lastaccess=\'' . time() . '\', ip=\'' . $database->escapeString(Util::remoteIP()) . '\' WHERE sessionid=\'' . $id . '\'');
if ($database->AffectedRows() > 0) {
return true;
}
$database->GetResult('INSERT INTO ' . $this->dbsessiontable . ' SET value=\'' . $database->escapeString($data) . '\', sessionid=\'' . $id . '\', lastaccess=\'' . time() . '\', ip=\'' . $database->escapeString(Util::remoteIP()) . '\'');
if ($database->AffectedRows() > 0) {
return true;
}
return false;
}
public function destroy ($id) {
$database = $this->database();
if (!$database) return false;
//$this->fw_session_log('info', 'destroy');
$id = preg_replace('/[^0-9a-z]/i', '', $id);
$database->GetResult('DELETE FROM ' . $this->dbsessiontable . ' WHERE sessionid=\'' . $id . '\'');
return true;
}
public function gc ($maxlifetime) {
$database = $this->database();
if (!$database) return false;
//$this->fw_session_log('info', 'gc');
$database->GetResult('DELETE FROM ' . $this->dbsessiontable . ' WHERE lastaccess< \'' . (time() - $maxlifetime) . '\'');
return true;
}