The header in php is mainly used to send the original http header to the client. It is commonly used to notify the browser that the page does not exist, delay redirection, indicate content type, declare downloaded files, and update the current document. Disable caching, display a login dialog requiring verification, etc.
[Recommended course:PHP Tutorial】
The header() function in PHP is used to send the original HTTP header to the client. Today I will share with you some commonly used header function headers in PHP. It has certain reference value and I hope it will be helpful to everyone.
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.ithhc.cn/'); //Jump to a new address
header('Refresh: 10; url=http://www.ithhc.cn/'); //Delayed redirection means jumping every few seconds
header('X-Powered-By: PHP/6.0.0'); //Modify X-Powered-By information
header('Content-language: en'); //Documentation Language
header('Content-Length: 1234'); //Set the content length
header('Last-Modified: '.gmdate('D, d M Y H:i:s' , $time).' GMT'); //Tell the browser the last modification time
header('HTTP/1.1 304 Not Modified'); //Tell the browser that the document content has not changed
Indicates the 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 that needs to be downloaded File
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') ;
The above is the detailed content of What is header in PHP. For more information, please follow other related articles on the PHP Chinese website!