闻心阁

一蓑烟雨看苍生,半壶浊酒笑红尘

PHP header函数

2012-10-23 约 3 分钟读完 搬砖秘籍

header()函数用来发送原始的HTTP报头。 常见的报头如下:

Content-Type: xxxx/yyyy Location: xxxx:yyyy/zzzz Status: nnn xxxxxx

使用教程:

跳转地址:

<?php
Header("Location: http://www.php.net");  
exit;
?>

返回状态:

<?php
header("Status: 404 Not Found");
?>

设置浏览器不进行缓存:

<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>

生成一个文件:

<?php
header("Content-type:application/pdf");

// 文件将被称为 downloaded.pdf header("Content-Disposition:attachment;filename='downloaded.pdf'");

// PDF 源在 original.pdf 中 readfile("original.pdf"); ?>

2 条评论

  1. 编程路上
    很不错,学习了
    1. Sailor 博主
      额,只是小记录。高手多多指教
Wordpress错误 Cannot modify header information 我们的青春和这个世界,隔着一层塑胶手套