Bug #76540 [Nab]: session_start() fails if headers already sent
| From: | tony at marston-home dot demon dot co dot uk | Date: | Thu, 28 Jun 2018 17:00:29 +0000 |
| Subject: | Bug #76540 [Nab]: session_start() fails if headers already sent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216019@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76540&edit=1
ID: 76540
User updated by: tony at marston-home dot demon dot co dot uk
Reported by: tony at marston-home dot demon dot co dot uk
Summary: session_start() fails if headers already sent
Status: Not a bug
Type: Bug
Package: Session related
Operating System: Windows 10
PHP Version: 7.2.7
Block user comment: N
Private report: N
New Comment:
You are correct. "session.use_cookies = 0" did the trick.
Previous Comments:
------------------------------------------------------------------------
[2018-06-28 10:42:13] spam2 at rhsoft dot net
yes it's a bug in your code and/or config
"session.use_cookies = 1" don't make any sense within a CLI script as well as
session_start() at all in most cases
------------------------------------------------------------------------
[2018-06-28 10:38:49] tony at marston-home dot demon dot co dot uk
Excuse me, but this *IS* a bug. When running PHP in CLI mode the use of cookies is irrelevant. They
are only relevant when running PHP through a browser. When the script starts in CLI mode the
$_COOKIE array is empty, and any cookies that are created are lost when the script terminates as
they cannot be passed on to another script. The check for headers/cookies already sent can therefore
be safely skipped when running in CLI mode.
------------------------------------------------------------------------
[2018-06-28 10:33:26] spam2 at rhsoft dot net
if(PHP_SAPI !== 'cli' && headers_sent() === false)
{
session_start();
}
------------------------------------------------------------------------
[2018-06-28 10:04:21] krakjoe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2018-06-28 09:56:04] tony at marston-home dot demon dot co dot uk
Description:
------------
When running a script in CLI mode I cannot open a new session if any headers have already been sent.
According to bug #28923 the original message concerned the session cookie, but cookies are only used
when running the script in a browser. If I am running in CLI mode there is no browser, so cookies
should be irrelevant, which means that session_start() should not fail.
Test script:
---------------
<?
flush();
session_start();
echo "here";
?>
Expected result:
----------------
Do not get warning.
Actual result:
--------------
session_start(): cannot start session when headers already sent
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76540&edit=1