header跳转(header头部定义有哪些)php中的header函数主要用于向客户端发送原始的http报头,常用的有用来通知浏览器页面不存在,延迟转向、表示内容类型、声明下载文件、对当前文档禁用缓存、显示一个需要验证的登陆对话框等等。
php中的header()函数用于向客户端发送原始的http报头,今天将为大家分享一些在php中常用的header函数头具有一定的参考价值,希望对大家有所帮助。
header('http/1.1200ok');//ok正常访问
header('http/1.1404notfound');//通知浏览器页面不存在
header('http/1.1301movedpermanently');//设置地址被永久的重定向301
header('location:http:///');//跳转到一个新的地址
header('refresh:10;url=http:///');//延迟转向也就是隔几秒跳转
header('x-powered-by:php/6.0.0');//修改x-powered-by信息
header('content-language:en');//文档语言
header('content-length:1234');//设置内容长度
header('last-modified:'.gmdate('d,dmyh:i:s',$time).'gmt');//告诉浏览器最后一次修改时间
header('http/1.1304notmodified');//告诉浏览器文档内容没有发生改变
表示内容类型
header('content-type:text/html;charset=utf-8');//网页编码
header('content-type:text/plain');//纯文本格式
header('content-type:image/jpeg');//jpg、jpeg
header('content-type:application/zip');//zip文件
header('content-type:application/pdf');//pdf文件
header('content-type:audio/mpeg');//音频文件
header('content-type:text/css');//css文件
header('content-type:text/javascript');//js文件
header('content-type:application/json');//json
header('content-type:application/pdf');//pdf
header('content-type:text/xml');//xml
header('content-type:application/x-shockw**e-flash');//flash动
声明一个下载的文件
header('content-type:application/octet-stream');
header('content-disposition:attachment;filename="itblog.zip"');
header('content-transfer-encoding:binary');
readfile('test.zip');
对当前文档禁用缓存
header('cache-control:no-cache,no-store,max-age=0,must-revalidate');
header('expires:mon,26jul199705:00:00gmt');
显示一个需要验证的登陆对话框
header('http/1.1401unauthorized');
header('www-authenticate:basicrealm="topsecret"');
声明一个需要下载的xls文件
header('content-disposition:attachment;filename=ithhc.xlsx');
header('content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('content-length:'.filesize('./test.xls'));
header('content-transfer-encoding:binary');
header('cache-control:must-revalidate');
header('pragma:public');
readfile('./test.xls');