Home > php教程 > php手册 > body text

php session_start()出错原因分析及解决方法

WBOY
Release: 2016-06-13 09:31:36
Original
1091 people have browsed it

错误提示: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

原因:在session_start()之前如果有输出内容,会出错,

解决办法:在session_start()之前加上ob_start();

index.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();
    }
?>
index2


index2.Php

复制代码 代码如下:


error_reporting(-1);
ob_start();//不加会出错,无法读取session
?
echo 1;
 session_start();

echo $_SESSION['password'];
var_dump($_SESSION);
?>
index

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!