PHP使用MySQL管理Session的回调函数详解
2023-06-13 09:15:02 时间
<?php
classMySessionextendsDBSQL{
/**
*__construct()
*/
publicfunction__construct(){
parent::__construct();
}
/**
*open()
*
*@param<String>$sSavePath
*@param<String>$sSessionNames
*
*@return<Boolean>true
*/
publicfunctionopen($sSavePath,$sSessionName){
returntrue;
}
/**
*close()
*/
publicfunctionclose(){
returntrue;
}
/**
*read()
*
*@param<String>$sSessionId
*@return<String>Sessiondataornullonerror...
*/
publicfunctionread($sSessionId){
$sSessionId=addslashes(trim($sSessionId));
$sSql="SELECT*FROMtb_sessionWHEREF_SessionId="{$sSessionId}"";
//echo$sSql;
if(false!=($result=$this->select($sSql))){
//var_dump($result[0]["F_SessionData"]);
return$result[0]["F_SessionData"];
}else{
return"";
}
}
/**
*write()
*
*@param<String>$SessionId
*@param<String>$sSessionData
*
*@return<Boolean>trueorfalse
*/
publicfunctionwrite($sSessionId,$sSessionData){
$arrSession=array();
$arrSession["F_SessionId"]=addslashes(trim($sSessionId));
$arrSession["F_SessionData"]=addslashes($sSessionData);
$arrSession["F_SessionCreated"]=date("Y-m-dH:i:s");
$arrSession["F_SessionUpdated"]=date("Y-m-dH:i:s",time()+1440);
//新session及更新的session
if(false!=($result=$this->insertData("tb_session",$arrSession))){
returntrue;
}else{
$arrUpdateSession=array();
$arrUpdateSession["F_SessionData"]=addslashes($sSessionData);
$arrUpdateSession["F_SessionUpdated"]=date("Y-m-dH:i:s",time()+1440);
if(false!=($result=$this->updateData("tb_session",""".addslashes($sSessionId).""","F_SessionId",$arrUpdateSession))){
returntrue;
}else{
returnfalse;
}
}
}
/**
*destroy()
*
*@param<String>$sSessionId
*@return<Boolean>true
*/
publicfunctiondestroy($sSessionId){
$sSessionId=addslashes(trim($sSessionId));
$this->delData($sSessionId,"F_SessionId","tb_session");
returntrue;
}
/**
*gc
*
*@param<int>$nMaxLifeTimeseconds
*
*@return<Boolean>true
*/
publicfunctiongc($nMaxLifeTime){
$dtExpiredTime=date("Y-m-dH:i:s",time()-$nMaxLifeTime);
$sSql="DELETEFROMtb_sessionWHEREF_SessionUpdated<{$dtExpiredTime}";
//echo$sSql;
$this->delete($sSql);
returntrue;
}
/**
*__desctruct()
*
*/
function__destruct(){
//ensuresessiondataiswrittenoutbeforeclassesaredestroyed
//(seehttp://bugs.php.net/bug.php?id=33772fordetails)
@session_write_close();
}//__destruct
}
?>
相关文章
- MySQL教程:更新多个字段(mysql更新多个字段)
- 使用 MySQL 查询指定字段的 Tips(mysql取指定字段)
- MYSQL长链接:构建坚固的数据连接(mysql长链接)
- 安装Mysql实现Mac环境更强劲的数据库(mysql在mac安装)
- 使用JSP连接MySQL数据库(jsp链接mysql)
- MySQL 服务丢失:担心的时刻来临(mysql服务消失)
- 习MySQL学习打造数据库技能攻略(mysql学)
- MySQL学习:使用SELECT语句获取日期的年份(mysql获取日期的年份)
- MySQL数据库如何进行增量备份?(mysql数据库增量备份)
- 安装MySQL服务才能使用本地数据库(本地没有mysql服务)
- 如何使用MySQL定义存储过程(mysql定义存储过程)
- MySQL存储过程练习:提升SQL技能(mysql存储过程练习题)
- 使用PHP 驱动MSSQL支撑稳固的开发环境(php mssql 驱动)
- 使用PHP和MSSQL实现网站搭建(php mssql 搭建)
- 查看MySQL数据库IP地址的小技巧(查看mysql数据库ip)
- Redis与MySQL:高效数据存储对比(redis 和mysql)
- MySQL中的窗口函数使用方法详解(mysql中使用窗口函数)
- 深入浅出MySQL中field字段的使用方法(mysql中filed)
- MySQL中的any函数使用方法简介(mysql中any怎么用)
- 使用外部Mysql数据库搭配CDH集群的心得(cdh使用集群外mysql)
- 使用CMD更换MySQL数据库版本(cmd更换mysql版本)
- 35岁,他只想学MySQL(35岁学mysql)
- MySQL分组查询语法详解(mysql中分组怎么写)
- MySQL持续无法执行可能的解决方案(mysql一直执行不了)
- MySQL 数据库如何上传至阿里云平台(mysql上传阿里云)
- 解决方案使用MariaDB代替MySQL在树莓派上运行(mysql不支持树莓派)
- MySQL存储过程存在风险,不建议使用(mysql不建议存储过程)
- MySQL 数据库中使用一二三四五排序方法达到排序的目的(mysql一二三四五排序)