This article mainly shares with you how to use the header() function in php. It mainly explains it to you in the form of code. I hope it can help you.
跳转页面 header('Location:'.$url); //Location和":"之间无空格。 2、 声明content-type header('content-type:text/html;charset=utf-8'); 3、 返回response状态码 header('HTTP/1.1 404 Not Found'); 4、 在某个时间后执行跳转 header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳转。
5. Control browser cache
Name | Meaning | Example |
---|---|---|
Expires | The date and time the response expires | Expires: Thu, 01 Dec 2010 16 :00:00 GMT |
Last-Modified | The last modified time of the requested resource | Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT |
Cache-Control | Tells all caching mechanisms whether they can be cached and what type | Cache-Control: no-cache |
Pragma | #Contains implementation-specific directives that can be applied to the response chain Any receiver | Pragma: no-cache |
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");
#6. Perform http verification
Name | Meaning | Example |
---|---|---|
##WWW-Authenticate
| Indicates the authorization scheme that the client requesting entity should useWWW-Authenticate: Basic |
7. Perform download operation
Meaning | Example | |
---|---|---|
The message header indicates in what form the reply content should be displayed, whether in inline form (that is, a web page or part of a page), or downloaded and saved as an attachment. to local. | Content-Disposition: attachment; filename="filename.jpg" |
Related recommendations: php: Detailed explanation of header() function usage examplesHow header() outputs image cache usage examples10 recommended articles about php header() functionheader('Content-Transfer-Encoding: binary'); //设置传输方式header('Content-Length: '.filesize('example.zip')); //设置内容长度Copy after loginThe above is the detailed content of How to use the header() function in php. For more information, please follow other related articles on the PHP Chinese website!