php - 304: Not modified and front end caching -


I am using PHP scripts to serve files. I would not like to send a 304 modified header in my HTTP response, if the client has not changed the file since the last time it downloaded, it is a feature in Apache (and most other web servers), but I have no clue about how this can be implemented through PHP.

I do not appear in my $ _ server super array > ' $ _ server [' HTTP_IF_MODIFIED_SINCE ']

< P> My question is not how to return a 304 header, but how will it be known that one should return?


Edit: The problem is that my $ _ server ['HTTP_IF_MODIFIED_SINCE'] is not set This is the contents of my .htaccess file :

  expires. Back type image on activity / JPEG "Amendment plus 1 month" time expires type image / png "Amendment plus 1 month" ends ByType Image / GIF Attach "Amendment plus 1 month" header cache control: "Required-Modify" & lt; IfModule mod_rewrite.c & gt; RewriteEngine On RewriteCond $ 1! ^ (Controller \ .php) RewriteRule (. * .jpg | * * .png | *. Gif) Controller .fp / $ 1 & lt; / IfModule & gt;  

HTTP_IF_MODIFIED_SINCE however $ _ server does not appear in the super array.

HTTP_IF_MODIFIED_SINCE is the correct way to do this if you are not getting this , Then see that Apache has enabled and worked properly. Borrowed From:

$ last_modified_time = filemtime ($ file); $ Etag = md5_file ($ file); // Always send header headers ("Last-Modified:". GMDATE ("D, Dm YH: I: S", $ last_modified_time). "GMT"); Header ("etag: $ etagon"); // exit if not modified (@strtotime ($ _ SERVER ['HTTP_IF_MODIFIED_SINCE']) == $ last_modified_time || @trim ($ _ SERVER ['HTTP_IF_NONE_MATCH']) == $ etag) {header ("HTTP / 1.1 304 not modified "); Go out; } // Output data

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -