Examples of php using the header function to set various HTTP headers
Release: 2016-07-25 09:04:39
Original
1005 people have browsed it
-
- /**
- desc: header function sets various HTTP headers
- link: bbs.it-home.org
- date: 2013/2/24
- */
- //Define encoding
- header( 'Content-Type: text/html;charset=utf-8 ');
-
- //Atom
- header ('Content-type: application/atom+xml');
-
- //CSS
- header('Content-type: text/css');
-
- //Javascript
- header('Content-type: text/javascript' );
-
- //JPEG Image
- header('Content-type: image/jpeg');
-
- //JSON
- header('Content-type: application/json');
-
- //PDF
- header(' Content-type: application/pdf');
-
- //RSS
- header('Content-Type: application/rss+xml; charset=ISO-8859-1');
-
- //Text (Plain)
- header( 'Content-type: text/plain');
-
- //XML
- header('Content-type: text/xml');
-
- // ok
- header('HTTP/1.1 200 OK');
-
- / /Set a 404 header:
- header('HTTP/1.1 404 Not Found');
-
- //Set the address to be permanently redirected
- header('HTTP/1.1 301 Moved Permanently');
-
- //Go to a New address
- header('Location: http://bbs.it-home.org/');
-
- //File delayed redirection:
- header('Refresh: 10; url=http://bbs.it-home .org/');
- print 'You will be redirected in 10 seconds';
-
- //Of course, it can also be implemented using html syntax
- //
- header('Content-Transfer-Encoding: binary');
- // load the file to send:
- readfile('example.zip');
-
- // Disable caching for the current document
- header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate') ;
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header('Pragma: no-cache');
-
- //Set 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 format
- header('Content-Type: image/jpeg'); //JPG***
- header('Content-Type: application/zip'); // ZIP file
- header(' Content-Type: application/pdf'); // PDF file
- header('Content-Type: audio/mpeg'); // Audio file
- header('Content-Type: application/x-shockw**e-flash '); //Flash animation
-
- //Show login dialog box
- header('HTTP/1.1 401 Unauthorized');
- header('WWW-Authenticate: Basic realm="Top Secret"');
- print 'Text that will be displayed if the user hits cancel or ';
- print 'enters wrong login data';
- ?>
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31