如何在使用session_set_save_handler时获取会话数据? 当我刷新页面时,如果我使用session_set_save_handler,所有会话数据都会丢失。但是,如果我删除session_set_save_handler,一切都是对的! 有代码
<?php
/*
Session open (called by session_start( ))
Session close (called at page end)
Session read (called after session_start( ) )
Session write (called when session data is to be written)
Session destroy (called by session_destroy( ) )
Session garbage collect (called randomly)
*/
function sess_open($sess_path, $sess_name) {
//print "Session opened.\n";
//print "Sess_path: $sess_path\n";
//print "Sess_name: $sess_name\n\n";
return true;
}
function sess_close( ) {
//print "Session closed.\n";
return true;
}
function sess_read($sess_id) {
//print "Session read.\n";
//print "Sess_ID: $sess_id\n";
return '';
}
function sess_write($sess_id, $data) {
//print "Session value written.\n";
//print "Sess_ID: $sess_id\n";
//print "Data: $data\n\n";
return true;
}
function sess_destroy($sess_id) {
//print "Session destroy called.\n";
return true;
}
function sess_gc($sess_maxlifetime) {
//print "Session garbage collection called.\n";
//print "Sess_maxlifetime: $sess_maxlifetime\n";
return true;
}
session_set_save_handler('sess_open','sess_close','sess_read','sess_write','sess_destroy','sess_gc');
session_register_shutdown('session_write_close');
session_start();
if(isset($_SESSION['foo']))
$_SESSION['foo'] = "have the foo data";
else $_SESSION['foo'] = "no foo data";
echo $_SESSION['foo'];
?>
当我刷新页面时,它始终输出&#39;没有foo数据&#39; 如果我删除
session_set_save_handler('sess_open','sess_close','sess_read','sess_write','sess_destroy','sess_gc');
session_register_shutdown('session_write_close');
它始终输出&#39;拥有foo数据&#39;。 谁能告诉我为什么?非常感谢!