Home >Backend Development >PHP Tutorial >Explanation of headersalreadysent error when using session_start_PHP Tutorial
Please see the detailed error program and output results
echo "testing ... ";
session_start();
?>
< ;/html>
The output is
testing ...
Warning: Cannot send session cookie - headers already sent by (output started at F:php2000test.php:2) in F:php2000test.php on line 4
Warning: Cannot send session cache limiter - headers already sent (output started at F:php2000test.php:2) in F:php2000test.php on line 4
Analysis:
Main reason, php.ini There is a definition of session. The default is to use cookies
[session]
session.use_cookies = 1; whether to use cookies
indicates that cookies are used to store sessions and the settings of cookies must be before the official htm. That is to say, it can only work in the header, so when this error occurs
we modify the program to
echo "testing ... ";
session_start();
?>
The same error, because echo has output
We modify the program to
$i=1;
session_start();
?>
Correct operation shows that there can be calculation statements in front of session_start, but there cannot be output statements
I tried to modify
session.use_cookies = 0; whether to use cookies
but it was not successful. Friends who hope to know the answer Notify me how to remove the cookie session