7 Ways to use PHP header ()

Source: Internet
Author: User

This article introduces the contents of the PHP header () 7 kinds of usage, has a certain reference value, now share to everyone, the need for friends can refer to

7 Ways to use PHP headers

1. Jump page

Header (' Location: '. $url);  There is no space between location and ': '.

2. Declaration Content-type

Header (' Content-type:text/html;charset=utf-8 ');

3. Return Response status Code

Header (' http/1.1 404 Not Found ');

4. Perform a jump after a certain time

Header (' refresh:10; url=http://www.baidu.com/');  Jump after 10s.

5. Control browser Cache

Header ("Expires:mon, Jul 1997 05:00:00 GMT"), Header ("Last-modified:". Gmdate ("D, D M Y h:i:s"). "GMT"); Header ("Cache-control:no-cache, must-revalidate"); Header ("Pragma:no-cache");

6.. Perform HTTP validation

Header (' http/1.1 401 Unauthorized '); header (' Www-authenticate:basic realm= ' Top Secret ');

7. Perform the download operation

Header (' Content-type:application/octet-stream '); Set Content Type header (' content-disposition:attachment; filename= ' Example.zip '); Set the MIME user as the attachment header (' content-transfer-encoding:binary '); Set the Transmit mode header (' Content-length: '. FileSize (' Example.zip ')); Set Content length

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.