PHP Header Function Tutorial _php tutorial

Source: Internet
Author: User
The header () function sends a raw HTTP header to the client. Header (String,replace,http_response_code) It is important to see that the title () must be sent in any so-called actual output

PHP Header Function Tutorial

Definition and usage
The header () function sends a raw HTTP header to the client.

It is important to see that the title () must be sent in any so-called actual output (in PHP 4 and later, you can use output buffering to solve this problem):

This results in an error.
The output above is before the header () call
Header (' location:http://www.example.com/');
?>

Grammar:

Header (String,replace,http_response_code)
Parameter
Description
String Required. The specified caption string is sent
Replace Optional Indicates whether the caption should supersede the previous or add a second caption. The default value is True (supersedes). False (allows multiple headings of the same type)
Http_response_code Optional Force HTTP response code to the specified value (available in PHP 4.3 and higher)

Hints and instructions Note: Since PHP 4.4 This feature can prevent more than one header from being sent at a time. This is a protection against head injection attacks. Example 1 prevents page caching:

Date in the Pastheader ("Expires:mon, Jul 1997 05:00:00 GMT"), Header ("Cache-control:no-cache"), Header ("Pragma:no-c Ache ");

Example 2 lets the user prompt to save the generated PDF file (the content disposition header is used to provide the suggested file name and forces the browser to display the Save dialog):

Header ("Content-type:application/pdf");

It'll be called Downloaded.pdfheader ("Content-disposition:attachment;filename= ' downloaded.pdf '");
The PDF source is in Original.pdfreadfile ("original.pdf");

http://www.bkjia.com/PHPjc/445505.html www.bkjia.com true http://www.bkjia.com/PHPjc/445505.html techarticle the header () function sends a raw HTTP header to the client. The header (String,replace,http_response_code) is important to see that the title () must be sent in any so-called actual output ...

  • 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.