PHP header () function detailed introduction and example _php Tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    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.