手机
当前位置:查字典教程网 >编程开发 >php教程 >php session_start()出错原因分析及解决方法
php session_start()出错原因分析及解决方法
摘要:错误提示:Warning:session_start()[function.session-start]:Cannotsendsession...

错误提示: 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>

【php session_start()出错原因分析及解决方法】相关文章:

php循环table实现一行两列显示的方法

php中smarty变量修饰用法实例分析

php删除指定目录的方法

php curl 获取https请求的2种方法

php开发中的页面跳转方法总结

JavaScript实现滚动栏效果的方法

php实现在服务器端调整图片大小的方法

WordPress博客程序常见错误的解决方法

php中get_defined_constants函数用法实例分析

php将字符串随机分割成不同长度数组的方法

精品推荐
分类导航