Forum Moderators: phranque
suzie250 wrote in [webmasterworld.com...] : <<<<<...If using a server with Apache, "if-modified-since" is set by default, but Apache cannot / does not respond to the "if modified-since" request on PHP files and will return a status 200 (ok). Therefore, I must include code in my php files to make the server respond to the request (because I do not have access to Apaches configuration). Just adding <?PHP header("Last-Modified: " . gmdate("D, d M Y H:i:s", getlastmod()) . " GMT");?> to the file does not work on it's own, I must also tell the user agent how to react to the status that it receives.
With a status of 200 on every php file, the user agent thinks that the page is always "fresh", and therefore graps the "newer" version. This causes unneeded bandwith usage and slows down load times.
Once I make sure I am understanding how "if-modified-since" works...>>>>>>>>
AND that is the exact point where I quit undersatnding to how to proceed further. I thing I've set php code well enough to send correct Last Modified headers for my dynamic pages. Well, maybe it doesn't reflect whatever changes happening at database level, just if the php script file is changed. But I'm Ok with it, not a problem for my site.
However that's apparently not sufficient to meet google's recommendation - just sending the Last Modified headers.
<<<<<...Just adding <?PHP header("Last-Modified: " . gmdate("D, d M Y H:i:s", getlastmod()) . " GMT");?> to the file does not work on it's own, I must also tell the user agent how to react to the status that it receives...>>>>>>
That's where I'm stuck, I guess. Anybody give me an idea of what is that code that is supposed to tell the user agent how to ract to the status that it receives?
Things like [webmasterworld.com...]
are too complicated for me, can't use it unless someone performes step-by-step instruction. However I hope my particular problem must be easier to resolve rather that stepping into this complex area.
You will want to call it from a php_prepend call in the .htaccess file, such as (all on one line):
php_value auto_prepend_file /usr/home/path to file/prepend_http.txt
Aftech much thinking and head scratching, I commented out the ETag headers. I wanted to send the last modified date for the file (I am using php includes for the headers and footers) and wanted to change the includes without affecting the last modified date. The ETag would change as the footer changed, so I deleted the header. It appears that ETags are not widely used by the search engines from some research I did.
Also, turn off the prepend call in any image subdirectories so the image is not sent with a varies header (due to the gzipping). This has a negative affect on the caching of images.
Ah, so much to learn....
[If the data is from a database, you may not be able to use the last modified date unless that information is a field in the database and you send that info]
made up sort of the following:
$this_mtime = filemtime($this_page);
$headers = apache_request_headers();
$if_time=$headers['If-Modified-Since'];
if ($this_mtime >= $if_mtime)
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $this_time).' GMT', true, 200);
else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $this_time).' GMT', true, 304);
Supposed to serve a very simple purpose. Would it?