php中的header的用法(我曾经在此放过过错)
来源:互联网 发布:武汉有戏网络怎么样 编辑:程序博客网 时间:2024/04/29 19:38
void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) : Send a raw HTTP header
下面有一些使用header的几种用法:
1、使用header函数进行跳转页面;
header('Location:'.$url);
其中$url就是将要跳转的url了。
这种用法的注意事项有以下几点:
Location 和":"之间不能有空格,否则会出现错误(注释:我刚测试了,在我本地环境下,没有跳转页面,但是也没有报错,不清楚什么原因); 在用header前不能有任何的输出(注释:这点大家都知道的,如果header之前有任何的输出,包括空白,就会出现header already sent by xxx的错误); header 后面的东西还会执行的;
2、使用header声明content-type
header('content-type:text/HTML;charset=utf-8');
这个没有什么好说的;
3、使用header返回response 状态码
header(sprintf('%s %d %s', $http_version, $status_code, $description));
样式就是这样的;
例如:header('HTTP/1.1 404 Not Found');
4、使用header在某个时间后执行跳转
header("Refresh: {$delay}; url={$url}");
其中$delay就是推迟跳转的时间,$url为需要跳转的url
例如:header('Refresh: 10; url=http://www.example.org/'); 意思为10s后跳转到http://www.eexample.org这个网站
5、使用header控制浏览器缓存
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进行下载操作
header('Content-Type: application/octet-stream');//设置内容类型
header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件下载 如果将attachment换成inline意思为在线打开
header('Content-Transfer-Encoding: binary');//设置传输方式
header('Content-Length: '.filesize('example.zip'));//设置内容长度
// load the file to send:
readfile('example.zip');//读取需要下载的文件
基本上就是上面这些 。。。
下面有一些使用header的几种用法:
1、使用header函数进行跳转页面;
header('Location:'.$url);
其中$url就是将要跳转的url了。
这种用法的注意事项有以下几点:
Location 和":"之间不能有空格,否则会出现错误(注释:我刚测试了,在我本地环境下,没有跳转页面,但是也没有报错,不清楚什么原因); 在用header前不能有任何的输出(注释:这点大家都知道的,如果header之前有任何的输出,包括空白,就会出现header already sent by xxx的错误); header 后面的东西还会执行的;
2、使用header声明content-type
header('content-type:text/HTML;charset=utf-8');
这个没有什么好说的;
3、使用header返回response 状态码
header(sprintf('%s %d %s', $http_version, $status_code, $description));
样式就是这样的;
例如:header('HTTP/1.1 404 Not Found');
4、使用header在某个时间后执行跳转
header("Refresh: {$delay}; url={$url}");
其中$delay就是推迟跳转的时间,$url为需要跳转的url
例如:header('Refresh: 10; url=http://www.example.org/'); 意思为10s后跳转到http://www.eexample.org这个网站
5、使用header控制浏览器缓存
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进行下载操作
header('Content-Type: application/octet-stream');//设置内容类型
header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件下载 如果将attachment换成inline意思为在线打开
header('Content-Transfer-Encoding: binary');//设置传输方式
header('Content-Length: '.filesize('example.zip'));//设置内容长度
// load the file to send:
readfile('example.zip');//读取需要下载的文件
基本上就是上面这些 。。。
- php中的header的用法(我曾经在此放过过错)
- php中的header用法
- header的用法(PHP)
- header的用法(PHP)
- header的用法(PHP)
- php header的用法
- php header的用法
- php header的用法小结
- php中header的用法
- php header的用法小结
- php header的用法小结
- php header()的用法总结
- PHP header的一些用法
- PHP中header的用法
- PHP中Header()的用法
- php中的header()函数
- 马伊俐父亲:请放过我的孩子
- 在此,我写下我的理想
- 自旋锁SPIN LOCK的编程实现
- Windows Live Writer
- 公共查询一张表的存储过程
- 谈谈.NET中常见的内存泄露问题——GC、委托事件和弱引用
- 深入浅出之JVM 内存编
- php中的header的用法(我曾经在此放过过错)
- 视频行业白热化,风行台网融合能否闯出一片天?
- Dictionary.Count 属性
- [转]我这一辈子学过的最有用的东西
- Java面向对象_多态
- Ubuntu下解压压缩方法总结
- RAKENT内核 - Timestamp时间戳
- include的返回值
- 《Ivor Horton's Beginning Java》 Chapter1-7 读书笔记