Home > Article > Backend Development > Why can't there be output before php header()?
There cannot be output before header() because both HTTP request and HTTP response have message headers, and message headers are composed of many header fields; if there is output before header, it will be sent with the default request first. , the message header has been determined, and subsequent settings will be invalid.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
Why can’t there be output before php header()?
Why can’t there be output before PHP header() session_start() function?
I didn’t answer the questions I encountered during the interview at the time. After checking some information, I still didn’t get the answer. I studied HTTP requests today and finally know the answer.
HTTP functions allow manipulation of information sent by the web server to the browser before other output is sent.
Both HTTP requests and HTTP responses have message headers. The message header is composed of many header fields.
That is, set the message header of the request before sending it; if there is output before, it will be sent with the default request first. The message header has been determined, and subsequent settings will be invalid.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Why can't there be output before php header()?. For more information, please follow other related articles on the PHP Chinese website!