百科 教育 动画 游戏 博览 网址 金融 搜搜 资料
触屏版

在线: 3495   » [用户登录]   QQ   » [注册]
close ◇ 读取数据,请稍候 Loading...

.: Welcome to flymote.com [flymot.com] :.



  »

◆ 其它资料:.

HTTP validator according to RFC2616 of HTTP/1.1

2005-05-22 20:25:44   李茂祥      阅读: 2326   【本类别其它资料】 【资料库首页
上一篇 收藏 打印 收藏夹 下一篇

〖HTTP validator according to RFC2616 of HTTP/1.1〗
// Autor: gallir@uib.es, header implementation for weak y strong
// HTTP validator according to RFC2616 of HTTP/1.1
// It's also compatible with HTTP/1.0 and
// take care of Netscape non-standard headers
// If more than 10800 secs have gone since last load
// it makes the client/cache to reload the page

// Call this function before doing anything else with databases or similar.

function DoHeaders($lastModified, $logged=FALSE) {
// $lastModified: last database modification, in "epochs"
//$logged: FALSE/TRUE // It takes in account that pages can be accessed
// as public or authorised

$now = time();
$maxCache = $now - 10800; // Max. time before refreshing
$headers = getallheaders();
$refresh=TRUE; // refresh, as default

if(isset($headers["If-Modified-Since"])) {
// NetCrap sends ";lenght = xxx" after the date
$arraySince = explode(";", $headers["If-Modified-Since"]);
$since = strtotime($arraySince[0]);
if($since >= $lastModified) $refresh=FALSE;
}

if($logged) {
$tag="\"AUT".$lastModified."\""; // A private page
} else {
$tag="\"PUB".$lastModified."\""; // and public one
}

if(isset($headers["If-None-Match"])) { // check ETag
if(strcmp($headers["If-None-Match"], $tag) == 0 )
$refresh=FALSE;
else
$refresh=TRUE;
}
if(!$refresh) {
header("HTTP/1.1 304 Not changed");
// The first header must be this
// otherwise Netcrap gives "No Data" error
$strLastModified = gmdate("r", $lastModified);
} else
$strLastModified = gmdate("r", $now);

header("ETag: $tag"); // The new TAG
header("Last-Modified: $strLastModified");
header("Expires: " . gmdate("r", time()+1));
header("Cache-Control: max-age=1, must-revalidate"); // HTTP/1.1
// Netscape doesn't handle very well the header("Pragma: no-cache");
if(!$refresh) {
ob_end_clean(); // Just in case..
die; // Don't do anything more
}
ob_start(); // We start buffering to allow "Content-Lenght" header
// at the end of the output to allow HTTP/1.0 persistent connections.
}


// Add following code at the end of your output

// If we allowed buffering before, we send the lenght
// to allow HTTP/1.0 persistent connections
function SendLength() {
if(ob_get_length()) {
header("Content-Length: " . ob_get_length());
ob_end_flush();
die; // Delete it if you don't want to finish the script
}
}


责任编辑:

【最近的搜索】:

上一篇 收藏 打印 收藏夹 下一篇
CopyRight(c) 2007 - 2020 All Rights Reserved  【赣ICP备12001042号】
触屏版 | Archiver 20200226 09:07 | 简介 | 帮助 | 留言 | 关于 | 360网站安全检测平台