Bug #73245 [Wfx]: session_start() doesn't start the session if headers have been sent
| From: | nikic@php.net | Date: | Tue, 11 Oct 2016 16:26:47 +0000 |
| Subject: | Bug #73245 [Wfx]: session_start() doesn't start the session if headers have been sent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204605@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73245&edit=1
ID: 73245
Updated by: nikic@php.net
Reported by: php at duncanc dot co dot uk
Summary: session_start() doesn't start the session if headers
have been sent
Status: Wont fix
Type: Bug
Package: Session related
Operating System: Linux
PHP Version: 7.1.0RC3
Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
@yasuo: As noted on the linked PR, it would be good to add an UPGRADING note about this.
Previous Comments:
------------------------------------------------------------------------
[2016-10-06 08:07:04] yohgaki@php.net
Not initializing $_SESSION by 2nd session_start() is not a bug actually, but it should fail to
initialize $_SESSION always when session_start() cannot be started. This is the objective for the
bug fix commit mentioned.
So real bug here is session module initializes $_SESSION even if it failed to start when there is no
output before 1st session_start().
This report's bug won't be fixed. I re-opened bug #71038.
------------------------------------------------------------------------
[2016-10-06 08:05:58] yohgaki@php.net
Related To: Bug #71038
------------------------------------------------------------------------
[2016-10-05 15:02:37] cmb@php.net
Indeed, it appears to break only if there is already some output
before the first session_start(). Try:
<?php
echo "start\n";
session_start();
$_SESSION['blah'] = 'foo';
var_dump($_SESSION);
session_write_close();
session_start();
var_dump($_SESSION);
------------------------------------------------------------------------
[2016-10-05 12:17:25] yohgaki@php.net
@cmd Thank you for investigation.
I'll look into this, but it seems I need more info. It works for me...
Perhaps, SAPI involved?
[yohgaki@dev PHP-7.1]$ ./php-bin
<?php
session_start();
$_SESSION['blah'] = 'foo';
var_dump($_SESSION);
session_write_close();
session_start();
var_dump($_SESSION);
?>
array(1) {
["blah"]=>
string(3) "foo"
}
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at
-:4) in - on line 7
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started
at -:4) in - on line 7
array(1) {
["blah"]=>
string(3) "foo"
}
------------------------------------------------------------------------
[2016-10-05 10:51:30] cmb@php.net
According to
git bisect the offending commit is
<https://github.com/php/php-src/commit/c200e8e1>.
Yasuo, can you please have a look at this issue.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=73245
--
Edit this bug report at https://bugs.php.net/bug.php?id=73245&edit=1