下面为session类的代码
复制代码 代码如下:
<?php
class session
{
static function init()
{
session_set_save_handler(
array("session","open"),
array("session","close"),
array("session","read"),
array("session","write"),
array("session","destroy"),
array("session","gc")
);
}
static function open($save_path,$session_name)
{
echo "session opening!<br>";
/*global $db,$REMOTE_ADDR;
$rs = $db->Execute("select * from Sessions where SessionID='".session_id()."'");
$arry=$rs->FetchRow();
if( $rs && $arry)
{
$db->Execute("update Sessions set SessionLast=NOW() where SessionID='".session_id()."'");
}
else
{
$query = "insert into Sessions set SessionID='".session_id()."',SessionName='$REMOTE_ADDR',SessionLast='NOW()'";
//echo $query;
$db->Execute($query);
}*/
return true;
}
static function close()
{
return(true);
}
static function read($id)
{
echo "session reading now!<br>";
global $db;
return true;
$timenow = strftime("%Y-%m-%d %H:%M:%S", time());
$query = "select SessionData from Sessions where SessionID='$id' and SessionLast > '$timenow'";
$rs = $db->Execute($query);
if(list($SessionData) = $rs->FetchRow())
{
//echo $SessionData;
return $SessionData;
}
else
{
return false;
}
}
static function write($id,$sess_data)
{
echo "session writing now!<br>";
global $db;
$rs = $db->Execute("select SessionID from Sessions where SessionID='$id'");
$num = $rs->RecordCount();
$unix_time = time()+MY_SESS_TIME;
//echo MY_SESS_TIME;
$dateleft = strftime("%Y-%m-%d %H:%M:%S", $unix_time);
if($num <= 0)
{
$sql = "insert into Sessions set SessionData='$sess_data', SessionName='".$_SERVER["REMOTE_ADDR"]."', SessionLast='$dateleft', SessionID='".session_id()."'";
}
else
{
$sql = "update Sessions set SessionData='$sess_data', SessionName='".$_SERVER["REMOTE_ADDR"]."', SessionLast='$dateleft' where SessionID='$id'";
}
$db->Execute($sql);
}
static function destroy($id)
{
echo "session destroying now!<br>";
global $db;
$sql = "DELETE FROM Sessions WHERE `SessionID` = '$id'";
$rs = $db->Execute($sql);
return $rs;
// $sess_file = "$sess_save_path/sess_$id";
//return(@unlink($sess_file));
}
/*********************************************
* WARNING - You will need to implement some *
* sort of garbage collection routine here. *
*********************************************/
static function gc($maxlifetime)
{
echo "session maxlifetime now!<br>";
global $db;
$timenow = strftime("%Y-%m-%d %H:%M:%S", time());
$sql = "DELETE FROM `$table_sessions` WHERE `SessionLast` < '$timenow'";
return $sess_db->Execute($sql);
//echo "now gc!<br>";
return true;
}
// proceed to use sessions normally
}
使用方法
复制代码 代码如下:
include("session.class.php");
session::init();
session_start();
define("MY_SESS_TIME", 3600); //SESSION 生存时长
$_SESSION["test"] = "abcdef";
自定义session
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 杨泰瑞《City Boy》[FLAC/分轨][159.66MB]
- APM亚流新世代《一起冒险》[320K/MP3][68.66MB]
- FIM《天伦乐》(DaydreamsAndLullabies)24K金碟[WAV+CUE]
- 【雨果唱片】中国管弦乐《鹿回头》
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO