I am using a PHP script to serve files.
I would like to be able to send back a 304
not modified header in my http response if the file has not changed since the client last downloaded it. This seems to be a feature in Apache (and most other web servers), but I have no clue how this can be implemented through PHP.
I have heard of using $_SERVER['HTTP_IF_MODIFIED_SINCE']
, but this variable does not seem to appear in my $_SERVER
super array.
My question is not how to return a 304
header, but how to know that one should be returned.
Edit: The problem is that my $_SERVER['HTTP_IF_MODIFIED_SINCE']
is not set. This is the content of my .htaccess
file:
ExpiresActive On
ExpiresByType image/jpeg "modification plus 1 month"
ExpiresByType image/png "modification plus 1 month"
ExpiresByType image/gif "modification plus 1 month"
Header append Cache-Control: "must-revalidate"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(controller.php)
RewriteRule (.*.jpg|.*.png|.*.gif) controller.php/$1
</IfModule>
HTTP_IF_MODIFIED_SINCE
still does not appear in the $_SERVER
super array.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…