📄 class.session.php
字号:
<?php
/*
文件名:session类
日期:10:00 2005-11-30
*/
/* Create new object of class */
$ses_class = new session();
/* Change the save_handler to use the class functions */
session_set_save_handler(array(&$ses_class, '_open'),
array(&$ses_class, '_close'),
array(&$ses_class, '_read'),
array(&$ses_class, '_write'),
array(&$ses_class, '_destroy'),
array(&$ses_class, '_gc'));
/* Start the session */
session_start();
if (!DEFINED("SESSION_LIFETIME")) DEFINE("SESSION_LIFETIME",10);
class session
{
/* Define the postgre table you wish to use with
this class, this table MUST exist. */
var $ses_table = "sessions";//sessions表
var $db;//初始化数据库类
var $debug=DEBUG;//出错信息显示,用于排错
function session(){
$this->db =sysdb::GetConnection();
}
/* Open session, if you have your own db connection
code, put it in here! */
function _open($path, $name) {
return true;
}
/* Close session */
function _close() {
return true;
}
/* Read session data from database */
function _read($ses_id) {
$ret= $this->db->getFirst("SELECT data FROM ".$this->ses_table." WHERE id='$ses_id';");
return $ret['data'];
}
/* Write new data to database */
function _write($ses_id, $data) {
$data=addslashes($data);
$rt=$this->db->getFirst("SELECT data FROM ".$this->ses_table." WHERE id='$ses_id';");
$uid=getuid();
if($rt!=''){
$idata=array(
'data'=>$data,
'uid'=>$uid,
"time"=>time());
if($this->db->update($this->ses_table,$idata," id='$ses_id'")&& $this->debug){
$this->db->seterror("写入错误update");
}
}
else{
$idata=array('id'=>$ses_id,
'data'=>$data,"time"=>time(),'uid'=>$uid);
$this->db->query("delete from ".$this->ses_table." where uid=$uid;");
if(!$this->db->insert($this->ses_table,$idata)&&$this->debug)
$this->db->seterror("写入错误insert!");
}
return true;
}
/* Garbage collection, deletes old sessions */
function _gc($life) {
$tm=time()- $life;
if(!$this->db->delete($this->ses_table,"time < $tm")&&$this->debug)
$this->db->seterror("错误 delete");
return true;
}
/*注销销毁session*/
function _destroy($ses_id){
//echo "destroy";
//echo $ses_id;
if(!$this->db->delete($this->ses_table,"id='$ses_id'")&&$this->debug)
$this->db->seterror("错误 delete");
return true;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -