Home > php教程 > PHP源码 > Common examples of commonly used headers in php

Common examples of commonly used headers in php

WBOY
Release: 2016-07-06 13:34:26
Original
1500 people have browsed it

The functions of headers in PHP include many jumps and sending header information. In addition to these two functions, are there other functions? Let's take a look at common examples of commonly used headers in PHP.

Record commonly used header information here


header('HTTP/1.1 200 OK'); // ok normal access
header('HTTP/1.1 404 Not Found'); //Notify the browser that the page does not exist
header('HTTP/1.1 301 Moved Permanently'); //Set the address to be permanently redirected 301
header('Location: http://www.ruonu.com/'); //Jump to a new address
header('Refresh: 10; url=http://www.ruonu.com/'); //Delayed redirection, that is, jump every few seconds
header('X-Powered-By: PHP/7.0.0'); //Modify X-Powered-By information
header('Content-language: en'); //Document language
header('Content-Length: 1234'); //Set content length
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //Tell the browser the last modified time
header('HTTP/1.1 304 Not Modified'); //Tell the browser that the document content has not changed

###Content Type###
header('Content-Type: text/html; charset=utf-8'); //Web page encoding
header('Content-Type: text/plain'); //Plain text format
header('Content-Type: image/jpeg'); //JPG, JPEG
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio file
header('Content-type: text/css'); //css file
header('Content-type: text/javascript'); //js file
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml
header('Content-Type: application/x-shockw**e-flash'); //Flash animation

######

###Declare a downloaded file###
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.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');
######

###Display a login dialog box that requires verification###
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
######


###Declare an xls file that needs to be downloaded###
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls');
######

?><script>ec(2);</script>

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template