Bug #76540 [Com]: session_start() fails if headers already sent

From: Date: Thu, 28 Jun 2018 10:33:28 +0000
Subject: Bug #76540 [Com]: session_start() fails if headers already sent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216008@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 Comment by: spam2 at rhsoft dot net 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: if(PHP_SAPI !== 'cli' && headers_sent() === false) { session_start(); } Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#216008) next »