跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

php中header()函数的使用方法

本文主要和大家分享 php 中header()函数的使用方法,主要以代码的方式和大家讲解,希望能帮助到大家。
跳转页面 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、控制浏览器缓存 名称含义示例
Expires
响应过期的日期和时间Expires: Thu, 01 Dec 2010 16:00:00 GMT
Last-Modified
请求资源的最后修改时间Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT
Cache-Control
告诉所有的缓存机制是否可以缓存及哪种类型Cache-Control: no-cache
Pragma
包括实现特定的指令,它可应用到响应链上的任何接收方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、执行http验证 名称含义示例
WWW-Authenticate
表明客户端请求实体应该使用的授权方案WWW-Authenticate: Basic
header('HTTP/1.1 401 Unauthorized');header('WWW-Authenticate: Basic realm="Top Secret"');
7、执行下载操作 名称含义示例
Content-Disposition
消息头指示回复的内容该以何种形式展示,是以内联的形式(即网页或者页面的一部分),还是以附件的形式下载并保存到本地。Content-Disposition: attachment; filename=”filename.jpg”
header('Content-Type: application/octet-stream'); //设置内容类型header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户
8、作为附件
header('Content-Transfer-Encoding: binary'); //设置传输方式header('Content-Length: '.filesize('example.zip')); //设置内容长度
相关推荐: 立即学习 “ PHP免费学习笔记(深入) ”; PHP 8.5.5 PHP 8.5.5 是 PHP 8.5 分支的维护更新版本。该版本延续了“小步快跑”的迭代逻辑,通过深度错误修复、底层性能微调以及安全加固,旨在为开发者提供一个更健壮、更高效的运行环境。该版本严格遵守语义化版本规范,不包含破坏性变更。 下载 php:header()函数用法实例详解 header()如何输出图片缓存用法实例 关于php header()函数的10篇文章推荐

相关文章