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