包含HEADERS_SENT的词条
php跳转到指定网址
?php
function redirect($url)
{
if(headers_sent()) {
return false;
}
if(substr($url, 0, 4) != 'http') {
$schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
$host = strlen($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$url = "$schema://$host$to";
}
header("HTTP/1.1 301 Moved Permanently");
// header("HTTP/1.1 302 Found")
// header("HTTP/1.1 303 See Other")
header("Location: $url");
exit();
}
$url = $_REQUEST['url'];
redirect($url);
?
php中开启SESSION的问题!
这个错误好像是session开启之前有输出值 你使用headers_sent()函数测试一下是否有输出值,这个函数的参数是file和line,在你报错的文件代码前写上
if(headers_sent($file,$line)) {
die("can not execute in " . $file . " in " . $line);
}试试 ,我也是遇到过这种情况的 和你分享一下
如何在HTTP headers设置有效日期?这个指的是在服务器上或者网页中加入的吗?怎么设置?求解
如果一个页面已经在你的浏览器中被缓存,那么你下次浏览时浏览器将会检测文档是否被修改过,那么它就会发送这样的头部:
If-Modified-Since: Sat, 28 Nov 2009 06:38:19 GMT
如果自从这个时间以来未被修改过,那么服务器将会返回“304 Not Modified”,而且不会再返回内容。浏览器将自动去缓存中读取内容
在PHP中,可以用$_SERVER['HTTP_IF_MODIFIED_SINCE'] 来检测。
// assume $last_modify_time was the last the output was updated
// did the browser send If-Modified-Since header?
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// if the browser cache matches the modify time
if ($last_modify_time == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// send a 304 header, and no content
header("HTTP/1.1 304 Not Modified");
exit;
}
}
-------------------------------------
或者可以这样来定义
-------------------------------------
在PHP中,你可以通过 header() 来设置头部响应信息。PHP已经自动发送了一些必要的头部信息,如 载入的内容,设置 cookies 等等… 你可以通过 headers_list() 函数看到已发送和将要发送的头部信息。你也可以使用headers_sent()函数来检查头部信息是否已经被发送。
Cache-Control
w3.org 的定义是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 其中“caching mechanisms” 包含一些你ISP可能会用到的 网关和代理信息。
例如:
以下是代码片段:Cache-Control: max-age=3600, public
“public”意味着这个响应可以被任何人缓存,“max-age” 则表明了该缓存有效的秒数。允许你的网站被缓存降大大减少下载时间和带宽,同时也提高的浏览器的载入速度。