1

I think I screwed up my website, this is an error I get on one of the pages
Warning : Cannot modify header information - headers already sent by (output started at /home/content/94/9066***/html/websites/{website name}.com/index.php:3) in /home/content/94/9066***/html/websites/{website name}.com/wp-includes/pluggable.php on line 896

How do I get rid of this? Thank you so much for your help!!

Moha the almighty camel
  • 4,327
  • 4
  • 30
  • 53
Tom
  • 1,223
  • 1
  • 16
  • 27

4 Answers4

1

You get this error because you're setting a header (most likely with the header function) after some output (body) have already been sent to the client, for example with a echo

The line of code + source file where the body output starts and where you attemp to set a header are in the error you receive.

The rule is first all headers are set then comes the body of the response.

Paolo
  • 15,233
  • 27
  • 70
  • 91
0

Or just because a line end... Check

<?php // is there a blank line before this one?
...
?> //same question
farvilain
  • 2,552
  • 2
  • 13
  • 24
0

Usually this warning is thrown when an output (even a space or a blank line) is sent to the browser before the session function call.

As this is happening on a wordpress site, did you modify any code in index.php?

Check if anything is echoed before the session_start() function call.

  • I was playing around with a javascript header input plugin and then had this problem – Tom Jan 05 '14 at 23:21
0

If we have a little knowledge about HTTP headers, we can fix "Headers already sent" errors. So I will touch just the overview of headers.

During a HTTP request, HTTP headers called [REQUEST HEADERS] are sent from client to the server and during a HTTP response, HTTP headers called [RESPONSE HEADERS] are sent from server to client.

Now, what the hell these headers contain?

REQUEST HEADERS--> Hostname,cookie info, the kind of encoding that the client accepts,etc.

RESPONSE HEADERS--> Content type being sent, info about Content encoding, etc.

You can get a lot of info about the headers in the below link:

http://code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039

In plain English, Headers contain information about the page being requested or sent.

Now Answering the ques:

Php header() function modifies the default RESPONSE headers and includes information that you want to send.

THUMBRULE: 

Since response headers contain info about the page being sent to client,
RESPONSE headers should be sent **FIRST** before the page itself.

So when you echo or display something to the browser and then use the header() function,

<?php

echo "hi";
header("As you have already displayed "hi", this info will not be sent.);
?>

In the above code we have actually sent the page and then trying to send our header info, so the headers will not be modified as the default headers were already sent and hence the error:
"Headers already sent".

Ans:

1) So, always include the header() function before displaying anything to the browser.

2)Another method to avoid the error is to use ob_start() function. This function just stores all the information that needs to be sent to the browser in a buffer memory, and it will output all at once.

Lets take a look at the code which will make more sense:

<?php
ob_start();
echo "hi";
echo "Hello"
header("This info will be sent");
ob_end_flush();
?>

In the above code, header info will be sent as both the echo statements will be stored in a buffer and will not be sent to the browser until the line ob_end_flush(); is executed. ob_end_flush() will just flush out the buffer memory sending all the info to the browser.

NOTE: But again make sure, you use the **ob_start()** function in the beginning.
Abhinav
  • 8,028
  • 12
  • 48
  • 89