Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,14 @@ PHP_FUNCTION(session_start)
* module is unable to rewrite output.
*/
if (PS(use_cookies) && SG(headers_sent)) {
php_error_docref(NULL, E_WARNING, "Session cannot be started after headers have already been 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_NOTICE, "Session cannot be started after headers have already been sent (started from %s on line %d)", output_start_filename, output_start_lineno);
} else {
php_error_docref(NULL, E_NOTICE, "Session cannot be started after headers have already been sent");
}
RETURN_FALSE;
}

Expand Down
19 changes: 19 additions & 0 deletions ext/session/tests/gh-16372.phpt
Original file line number Diff line number Diff line change
@@ -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

Notice: session_start(): Session cannot be started after headers have already been sent (started from %s on line %d) in %s on line %d
Loading