Header of PHP ()

Source: Internet
Author: User
Tags php script

The header () function is used to send the native HTTP header. Cannot have output before header ()!

1. About header information.

In the HTTP protocol, the HTTP message is: The request message sent by the client and the Respose response message sent by the server side.

Request message: HTTP header (Request line + request header) +http body (request body); Response message: HTTP header (status line + response header) +http body (response body)

The header information of this HTTP header is not the

Header information includes many things: see more: Www.cnblogs.com/aliang1992/p/6049578.html.

2. Examples of common header () functions:

The first: the "http/" will be used to calculate the HTTP status code to be sent.

For example, on an Apache server, where a PHP script handles a request for a nonexistent file, you want the script to respond to the correct status code.

<? PHP     Header ("http/1.0 404 Not Found");? >

The second type: Starting with "Location:", it not only sends messages to the browser, but also returns a status code to the browser.

Popular point, is automatically jump to http://www.example.com/URL address.

<? PHP     Header ("location:http://www.example.com/");     Exit ;? >

The Third Kind: the object type that starts with "Content-type:", tells the browser that the server responds.

For example: Application/xml text/xml and so on. Decide what form of browser handout, what encoding to read this file.

The fourth type: Specify the content attachment with "content-disposition:".

When the server side wants the client browser to send the file, if it is a browser-supported file type, it will usually be opened by default browser, such as Txt.jpg, will be displayed directly in the browser, if you need to prompt the user

The content-disposition should be used to deal with the preservation.

<? PHP     Header ("Content-disposition", "Attachment;filename=xxx.txt");? <

Header of PHP ()

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.