本文介紹了如何在 PHP 文件中使用 etags?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
你如何在 PHP 文件中實(shí)現(xiàn) etags?我要上傳什么到服務(wù)器,我要在 PHP 文件中插入什么?
How do you implemented etags inside a PHP file? What do I upload to the server and what do I insert into my PHP file?
推薦答案
創(chuàng)建/編輯您的 .htaccess 文件并添加以下內(nèi)容:
Create / edit your .htaccess file and add the following:
FileETag MTime Size
將以下內(nèi)容放在函數(shù)中或?qū)⑵浞旁谛枰?etags 處理的 PHP 文件的頂部:
Either place the following inside a function or put it at the top of the PHP file that you need etags to work on:
<?php
$file = 'myfile.php';
$last_modified_time = filemtime($file);
$etag = md5_file($file);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}
?>
這篇關(guān)于如何在 PHP 文件中使用 etags?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!