<?
$DB_SERVER = "伺服器"; /* 資料庫伺服器主機名稱 */
$DB_NAME = "資料庫名稱"; /* 資料庫名稱 */
$DB_USER = "根"; /* 資料庫使用者 */
$DB_PASS = "****************"; /* 資料庫密碼 */
$DB_SELECT_DB = "";
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");
函數 sess_open($save_path, $session_name) {
全域 $DB_SERVER、$DB_NAME、$DB_USER、$DB_PASS、$DB_SELECT_DB;
if (!$DB_SELECT_DB = mysql_pconnect($DB_SERVER, $DB_USER, $DB_PASS)) {
echo "抱歉!MYSQL 錯誤:無法以 $DB_USER 身分連線到 $DB_SERVER";
echo "MySQL 錯誤:", mysql_error();
死;
}
if (!mysql_select_db($DB_NAME, $DB_SELECT_DB)) {
echo "抱歉!MYSQL 錯誤:無法選擇資料庫 $DB_NAME";
死;
返回真
;
}
函數 sess_close() {
返回真;
}
函數 sess_read($SessionKey){
全域$DB_SELECT_DB,$SESS_LIFE;
$Query = "SELECT SessionArray FROM cdb_global_sessions WHERE SessionKey = '".$SessionKey."' AND SessionExpTime > " 。時間();
$結果 = mysql_query($Query, $DB_SELECT_DB);
if (列表($SessionArray) = mysql_fetch_row($Result)) {
返回$SessionArray;
返回假
;
}
函數 sess_write($SessionKey, $VArray) {
全域$DB_SELECT_DB,$SESS_LIFE;
$SessionExpTime = 時間() + $SESS_LIFE;
$SessionArray = addslashes($VArray);
$Query = "INSERT INTO cdb_global_sessions (SessionKey,SessionExpTime,SessionArray) VALUES ('".$SessionKey."','".$SessionExpTime."','".$SessionArray."')";
$結果 = mysql_query($Query, $DB_SELECT_DB);
如果(!$結果){
$Query = "UPDATE cdb_global_sessions SET SessionExpTime = '".$SessionExpTime."', SessionArray = '".$SessionArray."' WHERE SessionKey = '".$SessionKey."' AND SessionExpTime > " 。時間();
$結果 = mysql_query($Query, $DB_SELECT_DB);
}
回傳$結果;
}
函數 sess_destroy($SessionKey) {
全域$DB_SELECT_DB;
$Query = "從 cdb_global_sessions 中刪除,其中 SessionKey = '".$SessionKey."'";
$結果 = mysql_query($Query, $DB_SELECT_DB);
回傳$結果;
}
函數 sess_gc($maxlifetime) {
全域$DB_SELECT_DB;
$Query = "從 cdb_global_sessions WHERE SessionExpTime < " 中刪除。時間();
$結果 = mysql_query($Query, $DB_SELECT_DB);
返回 mysql_affected_rows($DB_SELECT_DB);
}
session_set_save_handler(
“會話開啟”,
“會話關閉”,
“sess_read”,
“sess_write”,
“sess_destroy”,
“sess_gc”);
會話開始();
?>