PHP Header Common instructions explained

Source: Internet
Author: User
Tags http authentication

The header in PHP is divided into three parts:

The first part: The version of the HTTP Protocol (http-version);
The second part: status code;
The third part: The reason phrase (reason-phrase).

Example code:

Return page HTTP information with the header command

1, the request page normal return
Header (' http/1.1 OK ');

2. Page Not found
Header (' http/1.1 404 Not Found ');

3, 301 Permanent Turn
Header (' http/1.1 301 Moved permanently ');
4. Restricted access
Header (' http/1.1 403 Forbidden ');
5. Server Error
Header (' http/1.1 Internal Server Error ');
6. Redirect to a new address
Header (' location:http://www.abcd9.com/');

Redirect after a period of delay
Header (' refresh:10; url=http://www.abcd9.com/'); 10 seconds delay

Overwrite x-powered-by value
Header (' x-powered-by:php/4.4.0 ');
Header (' x-powered-by:brain/0.6b ');

content language (en = 中文版)
Header (' content-language:en ');

Last modified time (can be used when caching)
$time = time () –60; or Filemtime ($FN), etc
Header (' last-modified: '. Gmdate (' d, D M Y h:i:s ', $time). ' GMT ');

tell the browser what to get is not updated
Header (' http/1.1 304 not Modified ');

set the length of the content (can be used when caching)
Header (' content-length:1234 ');

used to identify the download file
Header (' Content-type:application/octet-stream ');
Header (' content-disposition:attachment; filename= ' Abcd9.zip ');
Header (' content-transfer-encoding:binary ');

Disable caching of the current document
Header (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate ');
Header (' Expires:mon, Jul 1997 05:00:00 GMT ');

Set Content Type
Header (' content-type:text/html; Charset=utf-8 '); Encoded as Utf-8
Header (' Content-type:text/plain '); Plain text files
Header (' Content-type:image/jpeg '); JPG pictures
Header (' Content-type:application/zip '); ZIP Archive Package File
Header (' content-type:application/pdf '); PDF ebook File
Header (' Content-type:audio/mpeg '); MPEG (MP3,...) Audio files
Header (' Content-type:application/x-shockwave-flash '); Flash file

Displays the Login dialog box, which can be used for HTTP authentication
Header (' http/1.1 401 Unauthorized ');
Header (' Www-authenticate:basic realm= ' Top Secret ');
print ' Text that would be displayed if the user hits cancel or ';
print ' enters wrong login data ';

PHP Header Common instructions explained

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.