The PHP tutorial header () function is described in detail with an example
Grammar
Header (string,replace,http_response_code) parameter description
string is required. Specifies the string of headers to send.
Replace is optional. Indicates whether the header replaces the previous header, or adds a second header.
The default is true (replace). False (multiple headers of the same type are allowed).
Http_response_code is optional. Forces the HTTP response code to the specified value. (Available in PHP 4 and later)
The header () function sends the original HTTP header to the client.
It is important to recognize that the header () function must be called before any actual output is sent (in PHP 4 and later, you can use output caching to resolve this issue):
*/
Header ("X-sample-test:foo"); Send HTTP Headers
Header (' Content-type:text/plain '); Send HTTP Headers
Var_dump (Headers_list ()); Returns the list of headers sent
if (!headers_sent ())//If the header is not sent
{
Header (' location:http://www.example.com/'); Send headers
Exit End PHP Code
}
if (!headers_sent ($filename, $linenum))//If the specified file is not output
{
Header (' location:http://www.example.com/'); Send headers
Exit End PHP Code
}
else//If you have output to the specified file
{
echo "headers already sent in $filename on line $linenumn".
"Cannot redirect,for now, click this" href= "http://www.example.com" >LINKINSTEADN "; Output hint information
Exit End PHP Code
}
/*
Note: After PHP 4.4, this function prevents multiple headers from being sent at once. This is a protective measure against head-injection attacks.
*/
http://www.bkjia.com/PHPjc/631712.html www.bkjia.com true http://www.bkjia.com/PHPjc/631712.html techarticle the PHP tutorial header () function is described in detail with the instance syntax header (string,replace,http_response_code) parameter description string required. Specifies the string of headers to send. Replace is optional. To instruct ...