<?
$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”);
会话开始();
?>