錯誤提示: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
原因:在session_start()之前如果有輸出內容,會出錯,
解決辦法:在session_start()之前加上ob_start();
index.php
復制代碼 代碼如下:
<?php
error_reporting(-1);
ob_start();//不加會出錯,無法寫入session
register_shutdown_function('close');
echo 1;
session_start();
$_SESSION['password']='mima2ddddddddddddddda2';
function close()
{
if(session_id()!=='')
@session_write_close();
}
?>
<a href="index2.php" >index2</a>
index2.Php
復制代碼 代碼如下:
<?php
error_reporting(-1);
ob_start();//不加會出錯,無法讀取session
?
echo 1;
session_start();
echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>