0

I keep getting HEADERS ALREADY SENT in my logfile (system.log).

[6] /home/company/public_html/index.php:82
\</pre>
2018-09-17T10:49:23+00:00 DEBUG (7): HEADERS ALREADY SENT: \<pre>[0] /home/company/public_html/app/code/core/Mage/Core/Controller/Response/Http.php:52
[1] /home/company/public_html/lib/Zend/Controller/Response/Abstract.php:766
[2] /home/company/public_html/app/code/core/Mage/Core/Controller/Response/Http.php:83
[3] /home/company/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php:184
[4] /home/company/public_html/app/code/core/Mage/Core/Model/App.php:354
[5] /home/company/public_html/app/Mage.php:684
[6] /home/company/public_html/index.php:82
\</pre>

On line 82 of index.php there is the command Mage::run($mageRunCode, $mageRunType);

app/code/core/Mage/Core/Controller/Response/Http.php

public function sendHeaders()
{
    if (!$this->canSendHeaders()) {
        Mage::log('HEADERS ALREADY SENT: '.mageDebugBacktrace(true, true, true));
        return $this;
    }

I looked up canSendHeaders():

dev\lib\Zend\Controller\Response\Abstract.php

public function canSendHeaders($throw = false)
{
    $ok = headers_sent($file, $line);
    if ($ok && $throw && $this->headersSentThrowsException) {
        #require_once 'Zend/Controller/Response/Exception.php';
        throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
    }

But I don't understand it. The variables $file and $line are not defined anywhere, how should this even work?

index.php

<?php

if (file_exists("url_rewrites.php")) {
    include("url_rewrites.php");
}

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

if (file_exists("defines.php")) {
    include_once ("defines.php");
}

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
}

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run($mageRunCode, $mageRunType);
  • Can you please update your /home/company/public_html/index.php code in question So we can help you fastly this error comes when you are printing something before rendering page. – Rutvee Sojitra Sep 17 '18 at 12:50
  • @RutveeSojitra, I updated my question. – Black Sep 17 '18 at 13:00
  • if (version_compare(phpversion(), '5.2.0', '<')===true) { echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;"> <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"> <h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;"> Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>'; exit; } – Rutvee Sojitra Sep 17 '18 at 13:02
  • please comment this code and check if you issue will resolve let me know – Rutvee Sojitra Sep 17 '18 at 13:02
  • I can't tell, since the error does only come sometimes on unknown circumstances which I don't know yet. But I don't think that this is the cause, since we are using the correct php version. – Black Sep 17 '18 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.