Unknown WordPress warning

wordpress

#1

unknown WordPress warning. I confused. why display this warning.

Please help me.


#3

This is an important concept for you to understand before working with PHP, so I’ll go into detail for you to fully grasp the problem.

PHP has a feature called “output buffering” where any output (via echo/print etc) is stored in memory until it reaches a certain size. Only when it reaches that certain size does PHP actually send the output to the browser. This size is configurable in the php.ini.

Now, we all know that HTTP headers go before the body of a webpage. This means when you use header(“Location: …”) you’re only setting the header which MUST go at the top of the response, like this:

HTTP/1.1 200 OK
Location: /new/page

<!DOCTYPE HTML>
<html>
<head>
....

This also means that if PHP has already begun sending output to the visitor (the output buffer has reached the size limit), then you can no longer set any headers, because PHP has already sent the headers and the beginning of the body. At the same time, if your output is still all in memory, then PHP can still go in and set a header at the top of the response.

The error you’re seeing in that screenshot means exactly that! You’re trying to set headers, when PHP has already sent output to the visitor. You may not see it on your end because your output buffering is enabled, whereas the reviewer (and many of your future customers) have it disabled or configured very low in size.

So what’s the fix? Do not try to change the output buffer settings. You must properly separate your code so that any redirections occur before output begins. WordPress has hooks available which you can use for this purpose.

Relevant code sample:

ob_start(); // Start buffering output

echo "Hello, world.";
header("Location: https://envato.com"); // This will work

ob_flush(); // Force flush of output buffer (send all data now!)

header("X-Some-Header: 12345"); // Error - headers already sent