Home >Backend Development >PHP Problem >Why can't there be output before php header()?

Why can't there be output before php header()?

藏色散人
藏色散人Original
2021-09-22 14:45:192438browse

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.

Why can't there be output before php header()?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn