Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Using Correct Headers on Dynamic Pages: Discrepency with Google Sitemap

         

denisl

4:00 pm on Dec 10, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have always used the following in dynamic pages:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); // always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache");

When I first started with php about 7 years ago, I read that this was good as it would stop the dynamic pages from being chached - and as far as I know it has worked fine.

I am now working on my own Sitemap generator, and generating the Last Modified date from dates in a database showing when the data for that page was last edited.
Will there be a problem with this information being different to the header.
In any-case, a Last Modified date from the header of a file is going to be incorrect anyway, as the data in the database changes.

Receptional Andy

6:02 pm on Dec 10, 2008 (gmt 0)



Is there a reason why you want to defeat client-side caching? If you mean a dynamic page as in "the contents change on each page view" then that might make sense (although not necessarily). If you mean dynamic as in "generated by a server side script" then stopping caching just increases bandwidth use, and makes your site appear slower to visitors.

There's an outside chance Google might visit more frequently based on the misleading last-modified date, but more probably it will figure out that the date exactly matches the time of the request, and not bother doing so.

denisl

7:54 pm on Dec 10, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I take your point. I first used this on page where users logged in, having found that other users in my place of work were served exactly the same page - which was not what was required.

So if the present date is not put in the header, I assume the header will show the date the php file was created. Is it normal to feed a modified date from a database entry into the header to show when the page text was updated?

Receptional Andy

8:05 pm on Dec 10, 2008 (gmt 0)



Is it normal to feed a modified date from a database entry into the header to show when the page text was updated?

I wouldn't say it is normal or even common to supply last-modified headers. But I would certainly say it's best practice. It saves both you and Google bandwidth to do so and IMO knowing (and supplying information on) when content was last updated is useful in a way far beyond search engines.