{"id":3876,"date":"2022-08-20T21:33:54","date_gmt":"2022-08-20T16:03:54","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/"},"modified":"2022-08-20T21:33:54","modified_gmt":"2022-08-20T16:03:54","slug":"solved-how-to-fix-headers-already-sent-error-in-php","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/","title":{"rendered":"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-8028987\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"8028987\" data-parentid=\"8028957\" data-score=\"3248\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<h2>No output before sending headers!<\/h2>\n<p>Functions that send\/modify HTTP headers must be invoked <em><strong>before any output is made<\/strong><\/em>.<br \/>\n<kbd><strong>summary \u21ca<\/strong><\/kbd><br \/>\nOtherwise the call fails:<\/p>\n<blockquote>\n<p>Warning: Cannot modify header information &#8211; headers already sent (output started at <i>script:line<\/i>)<\/p>\n<\/blockquote>\n<p>Some functions modifying the HTTP header are:<\/p>\n<ul>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/header\"><code>header<\/code><\/a> \/ <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/header_remove\"><code>header_remove<\/code><\/a><\/li>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/session_start\"><code>session_start<\/code><\/a> \/ <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/session_regenerate_id\"><code>session_regenerate_id<\/code><\/a><\/li>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/setcookie\"><code>setcookie<\/code><\/a> \/ <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/setrawcookie\"><code>setrawcookie<\/code><\/a><\/li>\n<\/ul>\n<p>Output can be:<\/p>\n<ul>\n<li>\n<p><em>Unintentional:<\/em><\/p>\n<ul>\n<li>Whitespace before <code>&lt;?php<\/code> or after <code>?&gt;<\/code><\/li>\n<li>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/en.wikipedia.org\/wiki\/Byte_order_mark\">UTF-8 Byte Order Mark<\/a> specifically<\/li>\n<li>Previous error messages or notices<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><em>Intentional:<\/em><\/p>\n<ul>\n<li><code>print<\/code>, <code>echo<\/code> and other functions producing output<\/li>\n<li>Raw <code>&lt;html&gt;<\/code> sections prior <code>&lt;?php<\/code> code.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Why does it happen?<\/h2>\n<p>To understand why headers must be sent before output it&#8217;s necessary<br \/>\nto look at a typical <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a><br \/>\nresponse. PHP scripts mainly generate HTML content, but also pass a<br \/>\nset of HTTP\/CGI headers to the webserver:<\/p>\n<pre><code>HTTP\/1.1 200 OK\nPowered-By: PHP\/5.3.7\nVary: Accept-Encoding\nContent-Type: text\/html; charset=utf-8\n\n&lt;html&gt;&lt;head&gt;&lt;title&gt;PHP page output page&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;&lt;h1&gt;Content&lt;\/h1&gt; &lt;p&gt;Some more output follows...&lt;\/p&gt;\nand &lt;a href=\"\/\"&gt; &lt;img src=internal-icon-delayed&gt; &lt;\/a&gt;\n<\/code><\/pre>\n<p>The page\/output always <em>follows<\/em> the headers. PHP has to pass the<br \/>\nheaders to the webserver first. It can only do that once.<br \/>\nAfter the double linebreak it can nevermore amend them.<\/p>\n<p>When PHP receives the first output (<code>print<\/code>, <code>echo<\/code>, <code>&lt;html&gt;<\/code>) it will<br \/>\n<em>flush<\/em> all collected headers. Afterward it can send all the output<br \/>\nit wants. But sending further HTTP headers is impossible then.<\/p>\n<h2>How can you find out where the premature output occurred?<\/h2>\n<p>The <code>header()<\/code> warning contains all relevant information to<br \/>\nlocate the problem cause:<\/p>\n<blockquote>\n<p>Warning: Cannot modify header information &#8211; headers already sent by<br \/>\n<em><strong>(output started at<\/strong><\/em> \/www\/usr2345\/htdocs\/<b>auth.php:52<\/b>) in<br \/>\n\/www\/usr2345\/htdocs\/index.php on line 100<\/p>\n<\/blockquote>\n<p>Here &#8220;line 100&#8221; refers to the script where the <code>header()<\/code> <em>invocation<\/em> failed.<\/p>\n<p>The &#8220;<em>output started at<\/em>&#8221; note within the parenthesis is more significant.<br \/>\nIt denominates the source of previous output. In this example, it&#8217;s <code>auth.php<\/code><br \/>\nand <strong>line <code>52<\/code><\/strong>. That&#8217;s where you had to look for premature output.<\/p>\n<p><em>Typical causes:<\/em><\/p>\n<ol>\n<li>\n<h3>Print, echo<\/h3>\n<p>Intentional output from <code>print<\/code> and <code>echo<\/code> statements will terminate the opportunity to send HTTP headers. The application flow must be restructured to avoid that. Use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/function\">functions<\/a><br \/>\nand templating schemes. Ensure <code>header()<\/code> calls occur <em>before<\/em> messages<br \/>\nare written out.<\/p>\n<p>Functions that produce output include<\/p>\n<ul>\n<li><code>print<\/code>, <code>echo<\/code>, <code>printf<\/code>, <code>vprintf<\/code><\/li>\n<li><code>trigger_error<\/code>, <code>ob_flush<\/code>, <code>ob_end_flush<\/code>, <code>var_dump<\/code>, <code>print_r<\/code><\/li>\n<li><code>readfile<\/code>, <code>passthru<\/code>, <code>flush<\/code>, <code>imagepng<\/code>, <code>imagejpeg<\/code><\/li>\n<\/ul>\n<p> among others and user-defined functions.<\/p>\n<\/li>\n<li>\n<h3>Raw HTML areas<\/h3>\n<p>Unparsed HTML sections in a <code>.php<\/code> file are direct output as well.<br \/>\nScript conditions that will trigger a <code>header()<\/code> call must be noted<br \/>\nbefore <em>any<\/em> raw <code>&lt;html&gt;<\/code> blocks.<\/p>\n<pre><code>&lt;!DOCTYPE html&gt;\n&lt;?php\n    \/\/ Too late for headers already.\n<\/code><\/pre>\n<p>Use a templating scheme to separate processing from output logic.<\/p>\n<ul>\n<li>Place form processing code atop scripts.<\/li>\n<li>Use temporary string variables to defer messages.<\/li>\n<li>The actual output logic and intermixed HTML output should follow last.\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>Whitespace before <code>&lt;?php<\/code> for &#8220;script.php <strong>line 1<\/strong>&#8221; warnings<\/h3>\n<p>If the warning refers to output inline <strong><code>1<\/code><\/strong>, then it&#8217;s mostly<br \/>\nleading <strong>whitespace<\/strong>, text or HTML before the opening <code>&lt;?php<\/code> token.<\/p>\n<pre><code> &lt;?php\n# There's a SINGLE space\/newline before &lt;? - Which already seals it.\n<\/code><\/pre>\n<p>Similarly it can occur for appended scripts or script sections:<\/p>\n<pre><code>?&gt;\n\n&lt;?php\n<\/code><\/pre>\n<p>PHP actually eats up a <em>single<\/em> linebreak after close tags. But it won&#8217;t<br \/>\ncompensate multiple newlines or tabs or spaces shifted into such gaps.<\/p>\n<\/li>\n<li>\n<h3>UTF-8 BOM<\/h3>\n<p>Linebreaks and spaces alone can be a problem. But there are also &#8220;invisible&#8221;<br \/>\ncharacter sequences that can cause this. Most famously the<br \/>\n<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/en.wikipedia.org\/wiki\/Byte_order_mark\"><strong>UTF-8 BOM<\/strong> (Byte-Order-Mark)<\/a><br \/>\nwhich isn&#8217;t displayed by most text editors. It&#8217;s the byte sequence <code>EF BB BF<\/code>, which is optional and redundant for UTF-8 encoded documents. PHP however has to treat it as raw output. It may show up as the characters <code>\u00ef\u00bb\u00bf<\/code> in the output (if the client interprets the document as Latin-1) or similar &#8220;garbage&#8221;.<\/p>\n<p>In particular graphical editors and Java-based IDEs are oblivious to its<br \/>\npresence. They don&#8217;t visualize it (obliged by the Unicode standard).<br \/>\nMost programmer and console editors however do:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\" width=\"590\" height=\"140\" alt=\"joes editor showing UTF-8 BOM placeholder, and MC editor a dot\"><\/p>\n<p>There it&#8217;s easy to recognize the problem early on. Other editors may identify<br \/>\nits presence in a file\/settings menu (Notepad++ on Windows can identify and<br \/>\nremedy the problem),<br \/>\nAnother option to inspect the BOMs presence is resorting to an <strong>hexeditor<\/strong>.<br \/>\nOn *nix systems <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/linux.die.net\/man\/1\/hexdump\"><code>hexdump<\/code><\/a> is usually available,<br \/>\nif not a graphical variant which simplifies auditing these and other issues:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/1661011434_74_Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\" width=\"560\" height=\"87\" alt=\"beav hexeditor showing utf-8 bom\"><\/p>\n<p>An easy fix is to set the text editor to save files as &#8220;UTF-8 (no BOM)&#8221;<br \/>\nor similar to such nomenclature. Often newcomers otherwise resort to creating new files and just copy&amp;pasting the previous code back in.<\/p>\n<h3>Correction utilities <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.gif\" width=\"30\" height=\"20\"><\/h3>\n<p>There are also automated tools to examine and rewrite text files<br \/>\n(<code>sed<\/code>\/<code>awk<\/code> or <code>recode<\/code>).<br \/>\nFor PHP specifically there&#8217;s the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/freshcode.club\/projects\/phptags\"><code>phptags<\/code> tag tidier<\/a>.<br \/>\nIt rewrites close and open tags into long and short forms, but also easily<br \/>\nfixes leading and trailing whitespace, Unicode and UTF-x BOM issues:<\/p>\n<pre><code>phptags  --whitespace  *.php\n<\/code><\/pre>\n<p>It&#8217;s safe to use on a whole include or project directory.<\/p>\n<\/li>\n<li>\n<h3>Whitespace after <code>?&gt;<\/code><\/h3>\n<p>If the error source is mentioned as behind the<br \/>\nclosing <code>?&gt;<\/code><br \/>\nthen this is where some whitespace or the raw text got written out.<br \/>\nThe PHP end marker does not terminate script execution at this point. Any text\/space characters after it will be written out as page content<br \/>\nstill.<\/p>\n<p>It&#8217;s commonly advised, in particular to newcomers, that trailing <code>?&gt;<\/code> PHP<br \/>\nclose tags should be omitted. This <em>eschews<\/em> a small portion of these cases.<br \/>\n(Quite commonly <code>include()d<\/code> scripts are the culprit.)<\/p>\n<\/li>\n<li>\n<h3>Error source mentioned as &#8220;Unknown on line 0&#8221;<\/h3>\n<p>It&#8217;s typically a PHP extension or php.ini setting if no error source<br \/>\nis concretized.<\/p>\n<ul>\n<li>It&#8217;s occasionally the <code>gzip<\/code> stream encoding setting<br \/>\nor the <code>ob_gzhandler<\/code>.<\/li>\n<li>But it could also be any doubly loaded <code>extension=<\/code> module<br \/>\ngenerating an implicit PHP startup\/warning message.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>Preceding error messages<\/h3>\n<p>If another PHP statement or expression causes a warning message or<br \/>\nnotice being printed out, that also counts as premature output.<\/p>\n<p>In this case you need to eschew the error,<br \/>\ndelay the statement execution, or suppress the message with e.g.<br \/>\n<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/isset\"><code>isset()<\/code><\/a> or <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/@\"><code>@()<\/code><\/a> &#8211;<br \/>\nwhen either doesn&#8217;t obstruct debugging later on.<\/p>\n<\/li>\n<\/ol>\n<h2>No error message<\/h2>\n<p>If you have <code>error_reporting<\/code> or <code>display_errors<\/code> disabled per <code>php.ini<\/code>,<br \/>\nthen no warning will show up. But ignoring errors won&#8217;t make the problem go<br \/>\naway. Headers still can&#8217;t be sent after premature output.<\/p>\n<p>So when <code>header(\"Location: ...\")<\/code> redirects silently fail it&#8217;s very<br \/>\nadvisable to probe for warnings. Reenable them with two simple commands<br \/>\natop the invocation script:<\/p>\n<pre><code>error_reporting(E_ALL);\nini_set(\"display_errors\", 1);\n<\/code><\/pre>\n<p>Or <code>set_error_handler(\"var_dump\");<\/code> if all else fails.<\/p>\n<p>Speaking of redirect headers, you should often use an idiom like<br \/>\nthis for final code paths:<\/p>\n<pre><code>exit(header(\"Location: \/finished.html\"));\n<\/code><\/pre>\n<p>Preferably even a utility function, which prints a user message<br \/>\nin case of <code>header()<\/code> failures.<\/p>\n<h2>Output buffering as a workaround<\/h2>\n<p>PHPs <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.php.net\/manual\/en\/intro.outcontrol.php\">output buffering<\/a><br \/>\nis a workaround to alleviate this issue. It often works reliably, but shouldn&#8217;t<br \/>\nsubstitute for proper application structuring and separating output from control<br \/>\nlogic. Its actual purpose is minimizing chunked transfers to the webserver.<\/p>\n<ol>\n<li>\n<p>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/manual\/en\/outcontrol.configuration.php\"><code>output_buffering=<\/code><\/a><br \/>\nsetting nevertheless can help.<br \/>\nConfigure it in the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.php.net\/manual\/en\/configuration.file.php\">php.ini<\/a><br \/>\nor via <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.php.net\/manual\/en\/configuration.changes.php\">.htaccess<\/a><br \/>\nor even <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/manual\/en\/configuration.file.per-user.php\">.user.ini<\/a> on<br \/>\nmodern FPM\/FastCGI setups.<br \/>\nEnabling it will allow PHP to buffer output instead of passing it to the webserver instantly. PHP thus can aggregate HTTP headers.<\/p>\n<\/li>\n<li>\n<p>It can likewise be engaged with a call to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/ob_start\"><code>ob_start();<\/code><\/a><br \/>\natop the invocation script. Which however is less reliable for multiple reasons:<\/p>\n<ul>\n<li>\n<p>Even if <code>&lt;?php ob_start(); ?&gt;<\/code> starts the first script, whitespace or a<br \/>\nBOM might get shuffled before, rendering it ineffective.<\/p>\n<\/li>\n<li>\n<p>It can conceal whitespace for HTML output. But as soon as the application logic attempts to send binary content (a generated image for example),<br \/>\nthe buffered extraneous output becomes a problem. (Necessitating <code>ob_clean()<\/code><br \/>\nas a further workaround.)<\/p>\n<\/li>\n<li>\n<p>The buffer is limited in size, and can easily overrun when left to defaults.<br \/>\nAnd that&#8217;s not a rare occurrence either, difficult to track down<br \/>\nwhen it happens.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>Both approaches therefore may become unreliable &#8211; in particular when switching between<br \/>\ndevelopment setups and\/or production servers. This is why output buffering is<br \/>\nwidely considered just a crutch \/ strictly a workaround.<\/p>\n<p>See also the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.php.net\/manual\/en\/outcontrol.examples.basic.php\">basic usage example<\/a><br \/>\nin the manual, and for more pros and cons:<\/p>\n<ul>\n<li>What is output buffering?<\/li>\n<li>Why use output buffering in PHP?<\/li>\n<li>Is using output buffering considered a bad practice?<\/li>\n<li>Use case for output buffering as the correct solution to &#8220;headers already sent&#8221;<\/li>\n<\/ul>\n<h3>But it worked on the other server!?<\/h3>\n<p>If you didn&#8217;t get the headers warning before, then the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/manual\/en\/outcontrol.configuration.php\">output buffering<br \/>\nphp.ini setting<\/a><br \/>\nhas changed. It&#8217;s likely unconfigured on the current\/new server.<\/p>\n<h2>Checking with <code>headers_sent()<\/code><\/h2>\n<p>You can always use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/headers_sent\"><code>headers_sent()<\/code><\/a> to probe if<br \/>\nit&#8217;s still possible to&#8230; send headers. Which is useful to conditionally print<br \/>\ninfo or apply other fallback logic.<\/p>\n<pre><code>if (headers_sent()) {\n    die(\"Redirect failed. Please click on this link: &lt;a href=...&gt;\");\n}\nelse{\n    exit(header(\"Location: \/user.php\"));\n}\n<\/code><\/pre>\n<p>Useful fallback workarounds are:<\/p>\n<ul>\n<li>\n<h3>HTML <code>&lt;meta&gt;<\/code> tag<\/h3>\n<p>If your application is structurally hard to fix, then an easy (but<br \/>\nsomewhat unprofessional) way to allow redirects is injecting a HTML<br \/>\n<code>&lt;meta&gt;<\/code> tag. A redirect can be achieved with:<\/p>\n<pre><code> &lt;meta http-equiv=\"Location\" content=\"http:\/\/example.com\/\"&gt;\n<\/code><\/pre>\n<p>Or with a short delay:<\/p>\n<pre><code> &lt;meta http-equiv=\"Refresh\" content=\"2; url=..\/target.html\"&gt;\n<\/code><\/pre>\n<p>This leads to non-valid HTML when utilized past the <code>&lt;head&gt;<\/code> section.<br \/>\nMost browsers still accept it.<\/p>\n<\/li>\n<li>\n<h3>JavaScript redirect<\/h3>\n<p>As alternative a JavaScript redirect<br \/>\ncan be used for page redirects:<\/p>\n<pre><code> &lt;script&gt; location.replace(\"target.html\"); &lt;\/script&gt;\n<\/code><\/pre>\n<p>While this is often more HTML compliant than the <code>&lt;meta&gt;<\/code> workaround,<br \/>\nit incurs a reliance on JavaScript-capable clients.<\/p>\n<\/li>\n<\/ul>\n<p>Both approaches however make acceptable fallbacks when genuine HTTP header()<br \/>\ncalls fail. Ideally you&#8217;d always combine this with a user-friendly message and<br \/>\nclickable link as last resort. (Which for instance is what the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/php.uz\/manual\/en\/function.http-redirect.php\">http_redirect()<\/a><br \/>\nPECL extension does.)<\/p>\n<h2>Why <code>setcookie()<\/code> and <code>session_start()<\/code> are also affected<\/h2>\n<p>Both <code>setcookie()<\/code> and <code>session_start()<\/code> need to send a <code>Set-Cookie:<\/code> HTTP header.<br \/>\nThe same conditions therefore apply, and similar error messages will be generated<br \/>\nfor premature output situations.<\/p>\n<p>(Of course, they&#8217;re furthermore affected by disabled cookies in the browser<br \/>\nor even proxy issues. The session functionality obviously also depends on free<br \/>\ndisk space and other php.ini settings, etc.)<\/p>\n<h2>Further links<\/h2>\n<ul>\n<li>Google provides a <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.google.com\/search?q=php+headers+already+sent\">lengthy list of similar discussions<\/a>.<\/li>\n<li>And of course many specific cases have been covered on Stack Overflow as well.<\/li>\n<li>The WordPress FAQ explains <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/codex.wordpress.org\/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem.3F\">How do I solve the Headers already sent warning problem?<\/a> in a generic manner.<\/li>\n<li>Adobe Community: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/kb2.adobe.com\/community\/publishing\/505\/cpsid_50572.html\">PHP development: why redirects don&#8217;t work (headers already sent)<\/a><\/li>\n<li>Nucleus FAQ: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/faq.nucleuscms.org\/item\/79\">What does &#8220;page headers already sent&#8221; mean?<\/a><\/li>\n<li>One of the more thorough explanations is <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/web.archive.org\/web\/20080430141149\/http:\/\/www.expertsrt.com\/tutorials\/Matt\/HTTP_headers.html\">HTTP Headers and the PHP header() Function &#8211; A tutorial by NicholasSolutions<\/a> (Internet Archive link).<br \/>\nIt covers HTTP in detail and gives a few guidelines for rewriting scripts.<\/li>\n<\/ul>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">20<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to fix &#8220;Headers already sent&#8221; error in PHP <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] No output before sending headers! Functions that send\/modify HTTP headers must be invoked before any output is made. summary \u21ca Otherwise the call fails: Warning: Cannot modify header information &#8211; headers already sent (output started at script:line) Some functions modifying the HTTP header are: header \/ header_remove session_start \/ session_regenerate_id setcookie \/ setrawcookie Output &#8230; <a title=\"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\" aria-label=\"More on (Solved) How to fix &#8220;Headers already sent&#8221; error in PHP\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[423,339],"class_list":["post-3876","post","type-post","status-publish","format-standard","hentry","category-solved","tag-header","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>(Solved) How to fix &quot;Headers already sent&quot; error in PHP - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"(Solved) How to fix &quot;Headers already sent&quot; error in PHP - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] No output before sending headers! Functions that send\/modify HTTP headers must be invoked before any output is made. summary \u21ca Otherwise the call fails: Warning: Cannot modify header information &#8211; headers already sent (output started at script:line) Some functions modifying the HTTP header are: header \/ header_remove session_start \/ session_regenerate_id setcookie \/ setrawcookie Output ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-20T16:03:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP\",\"datePublished\":\"2022-08-20T16:03:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\"},\"wordCount\":1617,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\",\"keywords\":[\"header\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\",\"name\":\"(Solved) How to fix \\\"Headers already sent\\\" error in PHP - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\",\"datePublished\":\"2022-08-20T16:03:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"(Solved) How to fix \"Headers already sent\" error in PHP - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/","og_locale":"en_US","og_type":"article","og_title":"(Solved) How to fix \"Headers already sent\" error in PHP - JassWeb","og_description":"[ad_1] No output before sending headers! Functions that send\/modify HTTP headers must be invoked before any output is made. summary \u21ca Otherwise the call fails: Warning: Cannot modify header information &#8211; headers already sent (output started at script:line) Some functions modifying the HTTP header are: header \/ header_remove session_start \/ session_regenerate_id setcookie \/ setrawcookie Output ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/","og_site_name":"JassWeb","article_published_time":"2022-08-20T16:03:54+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP","datePublished":"2022-08-20T16:03:54+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/"},"wordCount":1617,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png","keywords":["header","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/","name":"(Solved) How to fix \"Headers already sent\" error in PHP - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png","datePublished":"2022-08-20T16:03:54+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-How-to-fix-Headers-already-sent-error-in-PHP.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-fix-headers-already-sent-error-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"(Solved) How to fix &#8220;Headers already sent&#8221; error in PHP"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/3876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=3876"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/3876\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=3876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=3876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=3876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}