Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve php header failure

Shulou Source: shulou.com Published: 2022-06-03 01:50:24 09月28日 Update

The main content of this article is "how to solve php header failure". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to solve php header failure"!

Resolve:

1. Cancel the space between the location and ":" symbols.

2. You can't have any output before using header.

3. Modify php.ini to open the cache, and modify "output_buffering=0" to 409.

Problem: input before header function

Generally speaking, you cannot output html content before the header function, similar to the setcookie () and session functions, which need to add header information to the output stream. If there are statements such as echo before the execution of header (), when header () is encountered later, it will report "Warning: Cannot modify header information-headers already sent by …." Mistake. That is to say, there cannot be any words, blank lines, carriage returns, etc., before these functions, and it is best to add the exit () function after the header () function. For example, the following error is written with a blank line between two php code snippets:

/ / this should be a blank line

Reason:

When the PHP script starts execution, it can send both the http message header (header) information and the body information. The http header (from the header () or SetCookie () function) is not sent immediately; instead, it is saved to a list. This allows you to modify the title information, including the default title (such as Content-Type title). However, once the script sends any output that is not a title (for example, using a HTML or print () call), PHP must first send all the Header and then terminate the HTTPheader. Then continue to send the subject data. From this point on, any attempt to add or modify Header information is not allowed, and one of the above error messages is sent.

At this point, I believe you have a deeper understanding of "how to solve php header failure". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Function information title content message output header blank line error body between script learning practical deeper generally speaking two code interest writing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Microsoft Redmi macOS