Home > Backend Development > PHP Tutorial > php session_start() error cause analysis and solution_PHP tutorial

php session_start() error cause analysis and solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:25:48
Original
862 people have browsed it

Error message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

Cause: If there is output content before session_start(), an error will occur,

Solution: Add ob_start() before session_start();

index.php

Copy code The code is as follows:

error_reporting(-1);
ob_start();//If you don’t add it, an error will occur and the session cannot be written.
register_shutdown_function('close');


echo 1;
session_start();

$_SESSION['password']='mima2ddddddddddddddda2';

function close()
{
if(session_id()!=='')
@session_write_close();
}
?>
index2

index2.Php
Copy code The code is as follows:

error_reporting(-1) ;
ob_start();//If you don’t add it, an error will occur and the session cannot be read.
?
echo 1;
session_start();

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824915.htmlTechArticleError message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent Reason: If there is output content before session_start(),...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template