Header php error header already sent by output started at

Error — Warning: Cannot modify header information — headers already sent by

Warning: Cannot modify header information — headers already sent by (output started at /home/ya3mblog/public_html/wp-login.php:59) in /home/ya3mblog/public_html/wp-includes/pluggable.php on line 866 website: ipublisharticles.com Error is at: ipublisharticles.com/wp-login.php?action=register

4 Answers 4

Add this code in wp-config.php on the first line:

ob_start(); error_reporting(0); 

Can anyone tell why this works? Couldn’t this lead to performance problems later? It works for me,too btw. I put it on top of functions.php.

I don’t think this is a great way to solve the issue, because you don’t solve the issue itself. You just «turn off» logging.

(This error) is usually because there are spaces, new lines, or other stuff before an opening tag, typically in wp-config.php.

Open the file with a plain text editor (like Notepad or BBEdit) and clear out the white space. Check that the very first characters are or a closing tag ?> with no blank lines or spaces after it. (FYI, a PHP file can run fine without the closing ?> tag.)

When saving, be sure the file encoding is not UTF-8 BOM but plain UTF-8 or any without the BOM suffix.

This could be true about some other file too, so please check the error message, as it will list the specific file name where the error occurred. Replacing the faulty file with one from your most recent backup or one from a fresh WordPress download is your best bet.

If the error message states: Warning: Cannot modify header information — headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42 , then the problem is at line #34 of wp-config.php, not line #42 of wp-login.php. In this scenario, line #42 of wp-login.php is the victim. It is being affected by the excess whitespace at line #34 of wp-config.php.

If the error message states: Warning: Cannot modify header information — headers already sent by (output started at /path/wp-admin/admin-header.php:8) in /path/wp-admin/post.php on line 569 , then the problem is at line #8 of admin-header.php, not line #569 of post.php. In this scenario, line #569 of post.php is the victim. It is being affected by the excess whitespace at line #8 of admin-header.php.

Источник

warning: can not modify header information -header already sent [duplicate]

Because you have the setcookie command after a bunch of whitespace. AKA:

If you still get this error, most likely you have similar whitespace inside session.php. Also, if you echo anything before the setcookie , you will have the same affect.

‘Whitespace’ is basically ANYTHING outside of the tags, and you can’t have ANY of this before a header or setcookie command.

In order to get rid of warnings/errors, you would set error_reporting(0) .

However, you should only do this in the production stage (when you put the website online). You should program your code so that there are not errors, even with error_reporting(E_ALL) .

The warnings are there for a reason. Don’t ignore them.

problem solved..i was using echo in session before setcookie..tell me one thing is it good to set cookie before i check session..beacuse by doing this this error will not be displayed..i sthere any problem in doing this

and one more question..i have read out TIP: If you are calling a cooking on the same page you plan to set one — be sure you retrieve it first, before you overwrite it! in my question i am first setting cooky and then retriving its value. is this wrong..should i use isset for checking whether same name cookie exists or not..am i wrong as i wrote code above for cookie

You shouldn’t set a cookie and then retrieve it. You should only set it once for use after the page, and then use internal variables in the script to pass it around.

  1. Any whitespace before sending headers is seen as output. therefore, the whitespace between the PHP tags must be eliminated.
  2. error_reporting(0); will supress all errors, but you should seek to fix and understand the errors instead of hide them.

edit: if you still want to report the errors, but just not display them to the user, use this: ini_set(‘display_errors’,’off’);

edit #2: to clarify, setcookie sends a header to the browser, all headers must be sent before anything is output. Therefore, you should also eliminate OR delay any output in session.php till after the cookies are set.

+1 for the «fix errors instead of hid[ing] them» comment. Far, far too many people seem to suppress even the simplest warnings, instead of taking the time to check and fix them. Best case scenario, it’s fine, and nothing’s really broken. Worst case, you’re hiding some behaviour that’s going to lead to an odd bug further down the line.

i dont get ur this line Therefore, you should also eliminate delay any output in session.php till after the cookies are set. I also tried by eliminating white space between two phps but still same error

To send a cookie, the server needs to set one or more Cookie headers. HTTP headers can’t be set once the actual body content has started going to the browser. To answer the second question first; you need to ensure that you’ve set cookies (and any other headers) before you send any output to the browser.

You’re seeing this problem because there’s whitespace (newlines) being emitted between sets of ?> and

To help with the wider issue, look into using output buffering (see ob_start() et al.) to help prevent output going to the browser before you’re ready for it.

You should setcookie as first thing in your code, even before the sesion.php. did you try that?

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

Cannot modify header information — headers already sent by (output [duplicate]

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/.com/index.php:3) in /home/content/94/9066***/html/websites/.com/wp-includes/pluggable.php on line 896

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

4 Answers 4

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.

Or just because a line end. Check

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.

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:

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,

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».

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:

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. 

Источник

Cannot modify header information [duplicate]

And the file trying to do the header redirect just includes this file at the top of the page and does the header lower down. Thanks in advance.

Your problem is that you want to redirect someone (using header) while there is already output written. After output is written, headers can’t be changed anymore.

If you’re using closing php tags ( ?> ) at the end of your class definition, check for a newline or any other whitespace character after that. If that’s the problem, I’d advice you to not use closing tags in class/function files.

The class you described doesn’t render any output, so I don’t see how you would get a header error. Can you add some of the page that loads the class?

4 Answers 4

What is triggering this error?

This error is triggered when some code has already output to the «screen» before you call the header function. Headers must be set before you output anything.

See the description from the header() PHP manual page:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

I am not outputting anything so what gives?

I would say that your code is generating an error somewhere. Try setting:

ini_set('display_errors', true); ini_set('error_reporting', ~0); 

In your index.php file as the very first set of commands.

Another possibility is that something somewhere is outputting a space or line return character. You cannot have any output of any kind before you call the header() function.

Possible solutions

There are two ways to fix this.

  1. Use output buffering to catch anything that might be echoed before you have set your headers
  2. Stop the code from outputting anything prematurely although this is a little more brittle

Option 1

To implement solution 1 you would put a call to ob_start() at the very beginning of your code (at the top of your bootstrap file or index.php usually).

Then once all logic has been completed and you are ready to output you would call ob_end_flush() to output everything in the buffer. Usually this would be at the very end of your index.php or bootstrap file.

Option 2

Zend Framework has the following in their coding guidelines to help mitigate the accidental output of new lines and spaces. See http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html#coding-standard.php-file-formatting.general:

For files that contain only PHP code, the closing tag («?>») is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.

Источник

Читайте также:  Python put json request
Оцените статью