本文是对php中session_start()的出错原因及解决方法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助
错误提示: 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
代码如下:
error_reporting(-1);
ob_start();//不加会出错,无法读取session
?
echo 1;
session_start();
echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>
?
错误提示: 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
代码如下:
unity http://www.unitymanual.com
<?phperror_reporting(-1);
ob_start();//不加会出错,无法读取session
?
echo 1;
session_start();
echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>
?
转载于:https://blog.51cto.com/unity3d168/1316613