Why does the header still return false?-php Tutorial

Source: Internet
Author: User
The header has been sent. Why does it still return false header ("Content-type: text/html; charset = gbk"); // send a header
$ A = headers_sent ();
Var_dump ($ a); // false

Why is false returned here ?????


Reply to discussion (solution)

Someone mentioned this in the manual:
Http://cn2.php.net/manual/en/function.headers-sent.php#86488

Someone mentioned this in the manual:
Http://cn2.php.net/manual/en/function.headers-sent.php#86488


I cannot understand English well. please explain it. Thank you.

Header ("Content-type: text/html; charset = gbk"); flush (); // refresh the output buffer var_dump (headers_sent ());

Header ("Content-type: text/html; charset = gbk"); flush (); // refresh the output buffer var_dump (headers_sent ());


Can I talk about some theoretical knowledge ??
For example, under what circumstances does headers_sent return true ??

It is very simple, as long as there is any output, or call flush
Both headers_sent return true.
For example
Header ("Content-type: text/html; charset = gbk ");
Echo "";
Var_dump (headers_sent ());

It is very simple, as long as there is any output, or call flush
Both headers_sent return true.
For example
Header ("Content-type: text/html; charset = gbk ");
Echo "";
Var_dump (headers_sent ());


Header ("Content-type: text/html; charset = gbk ");
Echo "";
Var_dump (headers_sent (); // here it is clearly false ?????????????

It is very simple, as long as there is any output, or call flush
Both headers_sent return true.
For example
Header ("Content-type: text/html; charset = gbk ");
Echo "";
Var_dump (headers_sent ());



I suspect you are wrong.

Bool headers_sent ([string & file [, int & line])

If the HTTP header has not been sent, headers_sent () returns FALSE; otherwise, returns TRUE. If the optional parameters file and line are specified, headers_sent () will put the PHP file name and the output from which line starts to the file and line variables.

Once the header has been sent, you cannot use the header () function to send other headers. Using this function can at least avoid errors related to HTTP headers. Another option is to use the output cache.

Php outputs the cache by default, so headers_sent always returns false
#3 flush () releases the content in the output cache (actually outputs), so the subsequent headers_sent returns true

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.