我在这里搜索了这个问题..但我无法得到正确的答案...所以请仔细阅读我的问题并回答我...谢谢提前..
-------------- Session.php ------------------------
<?php
class WSession
{
function __construct() {
}
function sess_open($sess_path, $sess_name) {
return true;
}
function sess_close() {
return true;
}
function sess_read($sess_id) {
mysql_connect("test", "test", "test");
mysql_select_db("test");
$result = mysql_query("SELECT Data FROM sessions WHERE SessionID = '$sess_id';");
if (!mysql_num_rows($result)) {
//Session found, pull out data field value
$sess_Data = $results->data;
$CurrentTime = time();
mysql_query("INSERT INTO sessions (SessionID, DateTouched) VALUES ('$sess_id', $CurrentTime);");
return $sess_Data;
} else {
$CurrentTime = time();
extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'sess');
mysql_query("UPDATE sessions SET DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
return "";
}
}
function sess_write($sess_id, $data) {
mysql_connect("test", "test", "test");
mysql_select_db("test");
$CurrentTime = time();
mysql_query("UPDATE sessions SET Data = '$data', DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
return true;
}
function sess_destroy($sess_id) {
mysql_connect("test", "test", "test");
mysql_select_db("test");
mysql_query("DELETE FROM sessions WHERE SessionID = '$sess_id';");
return true;
}
function sess_gc($sess_maxlifetime) {
mysql_connect("test", "test", "test");
mysql_select_db("test");
$CurrentTime = time();
mysql_query("DELETE FROM sessions WHERE DateTouched + $sess_maxlifetime < $CurrentTime;");
return true;
}
}
?>
------------------- Index.php ---------(MAIN FILE)----------------
require_once(session.php);
$handler = new WSession();
session_set_save_handler(array($handler, "sess_open"),
array($handler, "sess_close"),
array($handler, "sess_read"),
array($handler, "sess_write"),
array($handler, "sess_destroy"),
array($handler, "sess_gc"));
register_shutdown_function('session_write_close');
session_start();
$_SESSION['test'] = "testado";
然后,我们调用登录控制器(例如:login.php)。
---------------------- login.php ----------------------
重定向后,这里我们尝试使用保存处理程序保存会话。
$_SESSION['username'] = "XXXXXX";
$_SESSION['testing'] = "XXXXXX";
但它没有将上述值写入数据库。
它只存储主文件中的第一个数据,
test|s:9:"testado";
您能否指导保存其他值。