files: common/Common.config.php include/session.inc.php session_test.php get_session_test.php get_session_test2.php
Common.config.php <?php /* * Common config * By 恋太后天 */
/* * Database config */ define( "DBTYPE", "mysql" ); $database = array ( "mysql" => array ( "default" => array ( "host" => "localhost", "user" => "root", "password" => "", "dbname" => "" ), "session" => array ( "host" => "localhost", "user" => "session", "password" => "session", "dbname" => "sessions" ) ) );
?>
session.inc.php
<?php //使用mysql存放session 函数表 // by 恋太后天 2005-4-28
if (!isset($include_path)) $include_path = '''';
if (!is_array($database)) { include ($include_path."common/Common.config.php"); }
$DBsess = $database[DBTYPE]["session"]; $DBsess_link = mysql_connect($DBsess["host"], $DBsess["user"], $DBsess["password"]) or die ("Error:<em>Can not connect to Mysql server.</em>");
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");
function sess_open($path, $name) { return true; }
function sess_close() { return true; }
function sess_read($id) { global $DBsess , $DBsess_link; mysql_select_db($DBsess["dbname"]); $now = time(); $result = mysql_query("SELECT `data` FROM `sessions` WHERE `id`= ''$id'' AND `expiry_time` > $now", $DBsess_link); if (list($data) = mysql_fetch_row($result)) { return $data; } return false; }
function s |