hearder函数常用实例

一、可用作网页跳转
header("location:http://blog.csdn.net/zhaozzeng/");

二、定义编码

header( 'Content-Type:text/html;charset=utf-8 ');


三、强制禁止客户端浏览器缓存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");

四、输出页面表格
header('Content-type: application/xls');
header('Content-Disposition: attachment; filename=文件名.xls');
echo $table(表格字符串)

五、以PDF格式下载当前页面
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='文件名.pdf'");

六、输出json格式字符串
header('Content-Type: application/json; charset=utf-8');
echo json_encode($array);

七、文件延迟转向:

header('Refresh: 10; url=http://blog.csdn.net/zhaozzeng/');


八、提供简单的图片下载支持
url为绝对路径
header('Content-type: application/force-download');
header('Content-Transfer-Encoding: Binary');
header('Content-length: '.filesize($url));
header('Content-disposition: attachment; filename='.basename($url));
readfile($url);

九、网页出错处理
// 301
header("Location:http://blog.csdn.net/zhaozzeng/",TRUE,301); 、

// 302
header("Location:http://blog.csdn.net/zhaozzeng/",TRUE,302);

// 303
header("Location:http://blog.csdn.net/zhaozzeng/",TRUE,303);

// 307
header("Location:http://blog.csdn.net/zhaozzeng/",TRUE,307);

// 404 
header("Location:http://blog.csdn.net/zhaozzeng/",TRUE,404);
........

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值