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