php session_start()出錯原因分析及解決方法
更新時間:2013年10月28日 08:48:18 作者:
本文是對php中session_start()的出錯原因及解決方法進行了詳細的介紹,需要的朋友可以過來參考下,希望對大家有所幫助
錯誤提示: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
原因:在session_start()之前如果有輸出內(nèi)容,會出錯,
解決辦法:在session_start()之前加上ob_start();
index.php
復(fù)制代碼 代碼如下:
<?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
復(fù)制代碼 代碼如下:
<?php
error_reporting(-1);
ob_start();//不加會出錯,無法讀取session
?
echo 1;
session_start();
echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>
您可能感興趣的文章:
- php驗證session無效的解決方法
- phpmyadmin出現(xiàn)Cannot start session without errors問題解決方法
- ThinkPHP框架實現(xiàn)session跨域問題的解決方法
- ThinkPHP的cookie和session沖突造成Cookie不能使用的解決方法
- PHP錯誤WARNING: SESSION_START() [FUNCTION.SESSION-START]解決方法
- php5.3 不支持 session_register() 此函數(shù)已啟用的解決方法
- PHP關(guān)于IE下的iframe跨域?qū)е聅ession丟失問題解決方法
- php session_start()關(guān)于Cannot send session cache limiter - headers already sent錯誤解決方法
- PHP Session變量不能傳送到下一頁的解決方法
- PHP 出現(xiàn)亂碼和Sessions驗證問題的解決方法!
- php提示Failed to write session data錯誤的解決方法
相關(guān)文章
PHP靜態(tài)方法和靜態(tài)屬性及常量屬性的區(qū)別與介紹
今天小編就為大家分享一篇關(guān)于PHP靜態(tài)方法和靜態(tài)屬性及常量屬性的區(qū)別與介紹,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03