More information about the Underscore mailing list

[_] Error : PHP Warning: Cannot modify header information - headers already sent

Martin Moore martinm at it-helps.co.uk
Mon Mar 19 09:29:50 GMT 2018

Turns out I needed ob_start and ob-flush.

The odd thing is it was working at one point....


Martin.


On 19/03/2018, 00:23, "Underscore on behalf of Jeremy Prior" <underscore-bounces at under-score.org.uk on behalf of jeremy.prior at blueyonder.co.uk> wrote:

    
    
    > On Mon 19 Mar 2018, at 00:00:37, Martin Moore <martinm at it-helps.co.uk> wrote:
    > 
    > I'm getting a "PHP Warning:  Cannot modify header information - headers already sent by (output started at /var/www/codeclink/login/index.php:2) in /var/www/codeclink/login/index.php on line 158"
    > 
    > My understanding is that line 2 is causing problems.
    > 
    > 
    > This is line 158 :  header('location:home.php');
    > 
    > I've removed some things but can't work out what's wrong. Even done all the stuff Google suggests lol.
    > 
    > Top of the file:
    > 
    > <?php session_start(); ?> // THIS IS LINE 1
    > <html>
    >   <head>
    
    I'm not a PHP expert, but I have been bitten by this before.
    
    Basically, PHP will send whatever headers you tell it to, until you send some html.  Once you start sending html, you lose the ability to send additional headers.  The `<html>` in line 2 does exactly that.
    
    https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php#8028987 has a good explanation of this.  It looks like you are falling foul of "2. Raw HTML areas".
    
    You need to move you line 158 up to the top, or converting the PHP redirect into an HTML `META` tag or javascript redirect.
    
    ʝɛʑ
    -- 
    Jeremy Prior
    
    -- 
    underscore_ list info/archive -> http://www.under-score.org.uk/mailman/listinfo/underscore