|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-17 22:03 UTC] webmaster at jamescobban dot net
Description:
------------
The message Warning: Cannot modify header information - headers already sent is one of the big time-wasters of our profession. All of the documentation on this message including hundreds of web-pages and forum discussions end up as just a long list of things that the program MIGHT have done that would cause this message to appear. There is no documentation of exactly how a programmer should go about identifying exactly what the, usually trivial, mistake was that triggered the early send of the headers. The message should include information that directly points at the program action that caused PHP to send the headers.
Test script:
---------------
print ''; // empty string
header("Content-Type: application/json");
Expected result:
----------------
Warning: Cannot modify header information - headers already sent because of backtrace to line 1.
Actual result:
--------------
Warning: Cannot modify header information - headers already sent at line 2.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 21 05:00:01 2025 UTC |
> print ''; // empty string > header("Content-Type: application/json"); just don't echo / print anything ebfore headers, it's that easy > headers already sent is one of the big time-wasters just don't output anything when you intend send headers after, easy > All of the documentation on this message including > hundreds of web-pages and forum discussions just start your application with ob_start() and the problem is forever, easy