PHP header() 禁用缓存

来源:互联网 发布:淘宝平台费 编辑:程序博客网 时间:2024/04/24 07:03
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("Content-Language: charset=zh-cn");
说明字符集是简体中文

header("Content-type: text/html; charset=GB2312");
说明本页面是HTML内容,字符集是简体中文

使用范例
范例一: 本例使浏览器重定向到 PHP 的官方网站。
<?php
Header("Location: http://www.php.net";); 
exit;
?>
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.178-shop.com/");

范例二: 要使用者每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头
<?php
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( '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-store, no-cache, must-revalidate' );header( 'Cache-Control: post-check=0, pre-check=0', false );header( 'Pragma: no-cache' ); //兼容http1.0和https
**
范例三: 让使用者的浏览器出现找不到档案的信息。
<?php
header("Status: 404 Not Found");
?>
范例四:让使用者下载档案。<?php
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=文件名");
header("Content-Descrīption: PHP3 Generated Data");
?>

原创粉丝点击