The PHP code that executes on the server is typically used to respond to HTTP requests from the client. One of the simplest PHP files is this:
According to the HTTP standard, an HTTP message is generally divided into two parts: the HTTP header (header) and the HTTP body (body), and the header message must be output before the body message. In the PHP file, the header function can be used to output header information, and the echo command can output the body message, if you do not use the header function, before the output body will output the default header information. Therefore, for the following example:
Since there is a blank line at the front of the php file, PHP will output it as the body of the text, which will warn you that the header message has already been output after executing the headers function. In addition, some files use Unicode encoding, which can also cause this problem if you do not remove the BOM characters from the beginning of the file. There is no problem with blank lines on the last side of the php file, because PHP automatically removes a newline character after?>.
By the way, take a look at some common HTTP codes, which are listed below:
$ OK 201 Created-Bad Request 401 unauthorized 403 Forbidden 404 Not Found 405 Method not allowed 415 unsupported Med IA Type Internal Server Error
Resources:
[1] PHP Manual: First PHP page
[2] PHP Manual: Header
[3] PHP manual: Echo
[4] Hypertext Transfer Protocol--http/1.1
[5] HTTP Header detailed
[6] Modify HTTP Headers (Examples)
[7] PHP closed tag output extra empty exercise XML page display error
[8] HTTP status code-Wikipedia