PHP header () function

Source: Internet
Author: User
Tags http authentication

PHP header function usage example summary: hope to help you!
1. Not found on the page
Header ('HTTP/1.1 404 Not found ');
2. Use this header command to solve the 404 header generated by URL rewriting.
Header ('HTTP/1.1 200 OK ');
3. Restricted Access
Header ('HTTP/1.1 403 Forbidden ');
// The page moved permanently shoshould be used
// All redrictions, because search engines know
// What's going on and can easily update their URLs.
4. The page is permanently deleted. You can tell the search engine to update their URLs.
Header ('HTTP/1.1 301 moved permanently ');
5. Server Error
Header ('HTTP/1.1 500 internal server error ');
6. Redirect to a new location
Header ('location: http://www.example.org /');
7. Redirection after a delay of some time
Header ('refresh: 10; url = http://www.example.org /');
Echo 'you will be redirected in 10 seconds ';
8. Load the file to be downloaded:
Readfile('example.zip ');
9. You can also use HTML syntax to implement latency
Header ('content-transfer-encoding: Binary ');
10. Disable caching the current document:
Header ('cache-control: No-cache, no-store, Max-age = 0, must-revalidate ');
Header ('expires: Mon, 26 Jul 2010 05:00:00 gmt ');
Header ('pragma: No-cache ');
11. The logon dialog box is displayed for HTTP authentication.
Header ('HTTP/1.1 401 unauthorized ');
Header ('www-Authenticate: Basic realm = "top secret "');
Echo 'text that will be displayed if the user hits cancel or ';
Echo 'enters wrong login data ';
12. Set the content type:
Header ('content-type: text/html; charset = iso-8859-1 ');
Header ('content-type: text/html; charset = UTF-8 ');
Header ('content-type: text/plain '); // plain text file
Header ('content-type: image/JPEG '); // JPG picture
Header ('content-type: Application/zip'); // ZIP file
Header ('content-type: Application/pdf '); // PDF File
Header ('content-type: Audio/MPEG '); // audio MPEG (MP3,...) File
Header ('content-type: Application/X-Shockwave-flash'); // Flash Animation

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.