国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP 使用MySQL管理Session的回調(diào)函數(shù)詳解

2024-05-04 23:10:37
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:


<?php
class MySession extends DBSQL {

/**
* __construct()
*/
public function __construct() {
parent::__construct ();

}

/**
* open()
*
* @param <String> $sSavePath
* @param <String>$sSessionNames
*
* @return <Boolean> true
*/
public function open($sSavePath, $sSessionName) {
return true;
}

/**
* close()
*/
public function close() {
return true;
}

/**
* read()
*
* @param <String> $sSessionId
* @return <String> Session data or null on error...
*/
public function read($sSessionId) {
$sSessionId = addslashes(trim($sSessionId));
$sSql = "SELECT * FROM tb_session WHERE F_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> true or false
*/
public function write($sSessionId, $sSessionData) {
$arrSession = array();
$arrSession['F_SessionId'] = addslashes(trim($sSessionId));
$arrSession['F_SessionData'] = addslashes($sSessionData);
$arrSession['F_SessionCreated'] = date("Y-m-d H:i:s");
$arrSession['F_SessionUpdated'] = date("Y-m-d H:i:s", time() + 1440);

// 新session及更新的session
if (false != ($result = $this->insertData('tb_session', $arrSession))) {
return true;
} else {
$arrUpdateSession = array();
$arrUpdateSession['F_SessionData'] = addslashes($sSessionData);
$arrUpdateSession['F_SessionUpdated'] = date("Y-m-d H:i:s", time() + 1440);
if (false != ($result = $this->updateData('tb_session', "'".addslashes($sSessionId)."'", 'F_SessionId', $arrUpdateSession))) {
return true;
} else {
return false;
}
}
}

/**
* destroy()
*
* @param <String> $sSessionId
* @return <Boolean> true
*/
public function destroy($sSessionId) {
$sSessionId = addslashes(trim($sSessionId));
$this->delData($sSessionId, 'F_SessionId', 'tb_session');
return true;
}

/**
* gc
*
* @param <int> $nMaxLifeTime seconds
*
* @return <Boolean> true
*/
public function gc($nMaxLifeTime) {
$dtExpiredTime = date("Y-m-d H:i:s", time() - $nMaxLifeTime);

$sSql = "DELETE FROM tb_session WHERE F_SessionUpdated < {$dtExpiredTime}";
//echo $sSql;
$this->delete($sSql);

return true;
}
/**
* __desctruct()
*
*/
function __destruct() {
// ensure session data is written out before classes are destroyed
// (see ?id=33772 for details)
@session_write_close();
} // __destruct
}
?>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大安市| 阿坝| 白河县| 惠州市| 鄂尔多斯市| 靖边县| 敦煌市| 绵竹市| 大同县| 孟津县| 时尚| 平乡县| 贵溪市| 汪清县| 郸城县| 寿宁县| 兴城市| 罗城| 广饶县| 昌都县| 宁阳县| 祁连县| 新沂市| 新干县| 金华市| 台南县| 湖北省| 应用必备| 陕西省| 宁蒗| 南溪县| 上蔡县| 上高县| 桃园市| 聂荣县| 漠河县| 乐安县| 昌邑市| 万年县| 万年县| 依安县|