PHP常用http头

作者: 跨境工具箱 | 来源:发表于2017-01-10 08:48 被阅读100次

PHP常用Http

404

header('HTTP/1.1 404 Not Found');

301,302

#firefox中有时会缓存301跳转所以加上了缓存过期

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");

header('HTTP/1.1 301 Moved Permanently');

header('Location: '.$url,true,301);

附件下载

header("Cache-Control: must-revalidate,post-check=0,pre-check=0");

header("Content-Description: File Transfer");

header ("Content-type: application/octet-stream");

header ("Content-Length: " .filesize ($f_name));

header ("Content-Disposition: attachment; filename=" . basename($f_name));

readfile($f_name);

PHPExcel下载

$filename='联盟排行榜'.$date.'.xlsx';

header("Content-Type: application/force-download");

header("Content-Type: application/octet-stream");

header("Content-Type: application/download");

header('Content-Disposition:inline;filename="'.$filename.'"');

header("Content-Transfer-Encoding: binary");

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: must-revalidate, post-check=0, pre-check=0");

header("Pragma: no-cache");

$objWriter->save('php://output');

Excel

header('Content-Type: application/vnd.ms-excel');

header("Content-Disposition:attachment; filename=demo.xls");

header('Cache-Control: max-age=0');

原文链接:http://www.kubiji.cn/topic-id2507.html

相关文章

  • PHP常用http头

    PHP常用Http头 404 header('HTTP/1.1 404 Not Found'); 301,302 ...

  • php设置http头

    朋友忽然提了个问题,说自己模拟请求发送的时候和在浏览器中直接访问返回的字符串不一样,我猜应该是http头的问题,在...

  • PHP伪协议

    最常用的php://filter,用于读取文件/源码:http://127.0.0.1/xxx.php?file=...

  • http常用请求头

    协议头说明Accept可接受的响应内容类型(Content-Types)。Accept-Charset可接受的字符...

  • HTTP 常用请求头

    Accept 可接受的响应内容类型(Content-Types) Accept-Charset 可接受的字符集 A...

  • http header http常用请求头

    HTTP请求header 1.常用Requests部分2.常用Responses 部分3.不常用部分(可以不看)|...

  • 【HTTP】常用请求头字段

    协议头说明示例状态Accept可接受的响应内容类型(Content-Types)。Accept: text/pla...

  • 第二课时:websocket

    通过原生php实现websocket 新建静态页面 php的实现 请求头 必须是有效的http request 格...

  • window.location相关属性

    常用属性 例如这个网址:http://udn.yyuap.com/forum.php?mod=viewthread...

  • 常用的HTTP请求头与响应头

    HTTP消息头是指,在超文本传输协议( Hypertext Transfer Protocol ,HTTP)的请求...

网友评论

    本文标题:PHP常用http头

    本文链接:https://www.haomeiwen.com/subject/nxlkbttx.html