More information about the Underscore mailing list

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

Jeremy Prior jeremy.prior at blueyonder.co.uk
Mon Mar 19 00:19:19 GMT 2018


> 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