以下为引用的内容: <? $sess_dbh=""; $sess_maxlifetime=get_cfg_var("session.gc_maxlifetime");
function sess_open($save_path, $session_name) { global $hostname, $dbusername, $dbpassword, $dbname, $sess_dbh; www.phperz.com
//$sess_dbh=mysql_pconnect($hostname,$dbusername,$dbpassword) or die("不能连接数据库!"); $sess_dbh=mysql_pconnect(@#localhost@#,@#test@#,@#test@#) or die("不能连接数据库!"); www.phperz.com
// mysql_select_db("$dbname") or die("不能选择数据库!"); mysql_select_db(@#test@#) or die("不能选择数据库!"); return(true); } phperz~com
function sess_close() { //mysql_close(); return(true); } www~phperz~com
function sess_read($sid) { global $sess_dbh; www.phperz.com
$result = mysql_query("select data from sesslib where sid=@#$sid@#", $sess_dbh); $n=mysql_num_rows($result); if($n==0) { return(""); } else { $sess_data=mysql_result($result,0); return($sess_data); } } phperz.com
function sess_write($sid, $sess_data) { global $sess_dbh; if(!empty($sess_data)){ $r=mysql_query("insert into sesslib set sid=@#$sid@#,data=@#$sess_data@#,time=now()", $sess_dbh); if(!$r) { // insertion failed, means the session is already there, update it $r=mysql_query("update sesslib set sid=@#$sid@#, data=@#$sess_data@#, time=now() where sid=@#$sid@#",$sess_dbh); } return $r; }} php程序员之家
function sess_destroy($sid) { global $sess_dbh; www.phperz.com
$r=mysql_query("delete from sesslib where sid=@#$sid@#", $sess_dbh); return($r); } php程序员站
function sess_gc($maxlifetime) { global $sess_dbh, $sess_maxlifetime; phperz.com
$r=mysql_query("delete from sesslib where unix_timestamp(now())-unix_timestamp(time)>$sess_maxlifetime", $sess_dbh); return mysql_affected_rows($sess_dbh); } php程序员站
session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc"); phperz.com
?> www~phperz~com
|