|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-10-04 17:40 UTC] php at duncanc dot co dot uk
Description:
------------
In `7.0` and `5.6` calling `session_start()` even if headers have been sent still made `$_SESSION` usable, but `7.1` changes this behaviour.
Test script:
---------------
session_start();
$_SESSION['blah'] = 'foo';
var_dump($_SESSION);
session_write_close();
session_start();
var_dump($_SESSION);
Expected result:
----------------
The dumped array should be the same both times:
array(1) {
["blah"]=>
string(3) "foo"
}
Actual result:
--------------
The second array dump is empty
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
@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" }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);