mirror of
https://github.com/php/php-src.git
synced 2024-11-27 03:44:07 +08:00
Mention where headers were already sent if session_start fails (#16378)
We had previously improved where sessions were already started, and where headers were already sent when setting headers, but not where a header has been sent if we try to set the header cookie. Fixes GH-16372
This commit is contained in:
parent
275c7f21ab
commit
edf351ce6d
@ -2654,7 +2654,14 @@ PHP_FUNCTION(session_start)
|
||||
* module is unable to rewrite output.
|
||||
*/
|
||||
if (PS(use_cookies) && SG(headers_sent)) {
|
||||
/* It's the header sent to blame, not the session in this case */
|
||||
const char *output_start_filename = php_output_get_start_filename();
|
||||
int output_start_lineno = php_output_get_start_lineno();
|
||||
if (output_start_filename != NULL) {
|
||||
php_error_docref(NULL, E_WARNING, "Session cannot be started after headers have already been sent (sent from %s on line %d)", output_start_filename, output_start_lineno);
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "Session cannot be started after headers have already been sent");
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
19
ext/session/tests/gh-16372.phpt
Normal file
19
ext/session/tests/gh-16372.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
GH-16372: Mention where headers were already sent if session_start fails
|
||||
--EXTENSIONS--
|
||||
session
|
||||
--SKIPIF--
|
||||
<?php include('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
header("X-PHP-Test: test");
|
||||
|
||||
echo "Sent headers\n";
|
||||
|
||||
session_start();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Sent headers
|
||||
|
||||
Warning: session_start(): Session cannot be started after headers have already been sent (sent from %s on line %d) in %s on line %d
|
Loading…
Reference in New Issue
Block a user