P粉5433443812023-08-28 14:09:21
This occurs when your script attempts to send an HTTP header to the client but there has been output before, causing the header to have been sent to the client.
This is an E_WARNING
and it does not stop the script.
A typical example is a template file like this:
<html> <?php session_start(); ?> <head><title>My Page</title> </html> ...
session_start()
The function will attempt to send a header with the session cookie to the client. But PHP already sends the header when writing the element to the output stream. You have to move
session_start()
to the top.
You can solve this problem by looking at the line before the code that triggered the warning and checking where it is output. Move any header sending code before this code.
An often overlooked piece of output is the newline after PHP ends ?>
. It is considered standard practice to omit ?>
when it is the last thing in the file. Again, another common cause of this warning is when the starting is preceded by spaces, lines, or invisible characters, causing the web server to send headers and spaces/newlines, so when PHP starts parsing No headers will be submitted.
If you have multiple blocks in your file, there should not be any spaces between them. (Note: If you have auto-constructed code, you may have multiple blocks)
Also make sure there aren't any byte order marks in the code, such as when the script is encoded as UTF-8 with a BOM.
Related questions: