Analysis of error causes and solutions of php session_start of
- 2020-10-23 20:55:13
- OfStack
Error: Warning: session_start() [function.session-ES6en]: Cannot send cache ES11en-ES12en already sent
Reason: If there is output before session_start(), an error occurs,
Solution: Add ob_start() before session_start();
index.php
<?php
error_reporting(-1);
ob_start();// Can't write without an error 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();// Not adding will cause an error and cannot be read session
?
echo 1;
session_start();
echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>