您好,欢迎访问一九零五行业门户网

PHP header()的7种用法

这篇文章介绍的内容是关于php header()的7种用法 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
php header 的7种用法
1.  跳转页面
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. 控制浏览器缓存
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函数导出excel表格  
php header头部定义详解 
php header函数的用法总结
以上就是php header()的7种用法的详细内容。
其它类似信息

推荐信息