跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

PHP中header()函数的七种用法小结

目录PHP header()的7中用法:

1、跳转页面

2、声明 content-type

3、返回response状态码

4、定时执行跳转

5、控制浏览器缓存

6、执行http验证

7、下载

PHP header()的7中用法:

1、跳转页面

可以使用header()实现跳转页面功能。

header('Location:'.$url); // $url 跳转页面的地址2、声明 content-type调用API接口时,一般都会声明 content-type 的类型,否则无法读写数据。

header('content-type:text/html;charset=utf-8');header('content-type:application/json;charset=utf-8');

3、返回response状态码

header('HTTP/1.1 404 Not Found');

4、定时执行跳转

header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳转。在这里插入代码片

5、控制浏览器缓存

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、执行http验证

header('HTTP/1.1 401 Unauthorized');header('WWW-Authenticate: Basic realm="Top Secret"');

7、下载

header('Content-Type: application/octet-stream'); //设置内容类型header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件header('Content-Transfer-Encoding: binary'); //设置传输方式header('Content-Length: '.filesize('example.zip')); //设置内容长度到此这篇关于PHP中header()的七种用法小结的文章就介绍到这了,更多相关PHP header()用法内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:PHP使用header()输出图片缓存实例PHP header()函数常用方法总结Php header()函数语法及使用代码PHP header()函数使用详细(301、404等错误设置) PHP下利用header()函数设置浏览器缓存的代码php header()函数使用说明

相关文章