PHP header 的几种用法,你知道几种?
1. 跳转页面header('Location:'.$url); //Location和":"之间无空格。2. 声明content-typeheader('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");<br>
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");<br>
header("Cache-Control: no-cache, must-revalidate");<br>
header("Pragma: no-cache");6. 执行http验证header('HTTP/1.1 401 Unauthorized');<br>
header('WWW-Authenticate: Basic realm="Top Secret"');7. 执行下载操作header('Content-Type: application/octet-stream'); //设置内容类型<br>
header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件<br>
header('Content-Transfer-Encoding: binary'); //设置传输方式<br>
header('Content-Length: '.filesize('example.zip')); //设置内容长度更多【干货分享】,请关注一位有情怀的工程师。
AD:真正免费,域名+虚机+企业邮箱=0元
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号