小编apa*_*pak的帖子

使用 php 生成 php 电子标签

此 PHP 代码为 xml 文件生成 eTag。问题是 eTag 仅当文件本身更新/修改时才会更新。当动态结果更新时,我也需要更新 etag。知道如何做到这一点吗?

//get the last-modified-date of this very file
$lastModified=filemtime(__FILE__);

//get a unique hash of this file (etag)
$etagFile = md5_file(__FILE__);

//get the HTTP_IF_MODIFIED_SINCE header if set
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);

//get the HTTP_IF_NONE_MATCH header if set (etag: unique file hash)
$etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false);

//set last-modified header
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT");

//set etag-header
header("Etag: $etagFile");

//make sure caching is turned on    
//check if page has changed. …
Run Code Online (Sandbox Code Playgroud)

php xml apache etag cache-control

2
推荐指数
1
解决办法
8330
查看次数

标签 统计

apache ×1

cache-control ×1

etag ×1

php ×1

xml ×1