Summary of header usage in PHP, Phpheader usage Summary _php Tutorial

Source: Internet
Author: User
Tags getting started with php

Summary of header usage in PHP, summary of Phpheader usage


This article summarizes the usage of headers in PHP. Share to everyone for your reference, as follows:

The function of the header () function in PHP is to send header information to the client.

What is header information?

Here is a simple explanation, detailed self-view HTTP protocol.

In the HTTP protocol, the server-side answer (response) content consists of two parts: header information and body content, where the header information is not part of the HTML, and the body content is not </body>. The header information is invisible to the user and contains many items, including: Server information, date, length of content, etc. The body content is the entire HTML, which is all you can see.

What is the use of the header information?

The function of the head information is many, the main one has the following several:

1. Jump:

Header ("REFRESH:2; Url=http://localhost//session.php ");//2 seconds after the jump

If the wait time is 0, it is equivalent to the header ("Location:").

Header ("location:http://localhost//session.php");//Direct jump

2, the content of the specified page:

The same XML file, if specified in the header information: Content-type:application/xml, the browser will parse it according to the XML file format. However, if the header message is: Content-type:text/xml, the browser will treat it as a text parsing. (The browser does not parse the file by extension)

3, Accessories Download:

$filename = "Tupian.jpg"; The file path can be either an absolute path or a relative path header (' content-type:application/x-jpg '); The type of the file header (' content-disposition:attachment; Filename= ' is saved with the filename. jpg "'); Download the displayed name ReadFile ("$filename"); exit ();

View:

$link = "Tupian.jpg"; The file path can be either an absolute path or a relative path//$link = "New text document. xml"; The file path can be either an absolute path or a relative path if (Isset ($link)) {  Header ("http/1.1 303 See Other");  Header ("Location: $link");  Exit;}

More about PHP related content readers can view the topic: "PHP File Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133091.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133091.html techarticle Summary of header usage in PHP, Phpheader usage Summary This article summarizes the usage of headers in PHP. Share to everyone for reference, as follows: The function of the header () in PHP is to give the customer ...

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