找回密码
 注册
查看: 784|回复: 0

PHP header 的7种用法

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2022-5-31 15:00:07 | 显示全部楼层 |阅读模式
PHP header 的7种用法1. 跳转页面
+ N, z1 V; V  q% Aheader('Location:'.$url);  //Location和":"之间无空格。/ J& o+ S& ^1 F1 H" k: N; V" ?
2. 声明content-type
# C5 ?3 [# h3 L; {5 }% y, Yheader('content-type:text/html;charset=utf-8;charset=gbk');3. 返回response状态码6 O( }* d2 ^( C* f
header('HTTP/1.1 404 Not Found');4. 在某个时间后执行跳转3 n, S9 i( j  j5 C9 L, F2 o/ _
header('Refresh: 10; url=http://www.bbs168x.cn/');  //10s后跳转。5. 控制浏览器缓存
( N% S) n6 v0 f7 i' F; u+ A
$ s* f  O" d4 Vheader("Expires: Ture, 31 2022 09: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验证0 M" G  \  s9 _7 r; I6 o" \2 I
header('HTTP/1.1 401 Unauthorized');header('WWW-Authenticate: Basic realm="Top Secret"');
# g8 m! N, Q9 j- p4 }! D7. 执行下载操作
" o5 }) U" q6 I% V' [6 N
- n  S  C, U6 i  \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')); //设置内容长度  X% _3 T4 k4 k5 C( ]& D- V  c
% k" n; E' z2 Q( f8 w. f
相关推荐:php header函数导出excel表格PHP header头部定义详解php header函数的用法总结以上就是PHP header()的7种用法的详细内容,更多请关注php中文网其它相关文章!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-11 23:15 , Processed in 0.018930 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表