hearder函数常用实例

来源:互联网 发布:齐鲁软件杯 编辑:程序博客网 时间:2024/05/21 08:44
一、可用作网页跳转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
原创粉丝点击