The Most Active and Friendliest
Affiliate Marketing Community Online!

“Propeller”/  Direct Affiliate

"if modified since" this is a nightmare to find out

nazar

New Member
affiliate
a really good idea, but i am beginning to hate that google brought this up:fool:
as i can't find out what i want (and i have searched a lot)

as i don't have ten posts, (so i can't give you the link) - i will just copy and paste what google said in one of her webmaster help pages.

google says
Make sure your web server supports the If-Modified-Since HTTP header. This feature allows your web server to tell Google whether your content has changed since we last crawled your site. Supporting this feature saves you bandwidth and overhead.

google link :clap: but it's not a link (had to break the page down) - okay, i submitted 10 quick posts so you could get the link

Webmaster guidelines - Webmasters/Site owners Help


from what i have read/seen on the internet - this is a really good idea

my question is - do i have to put any code into my webpage to use this or does my server handle the whole thing (as they do support "if modified since")

any help would be appreciated
 
Its usually not important with static pages, since your server generally spit out the correct headers.

But if you are using php, like me, then its worth to consider. Its not as important on low-traffic sites, as on higher traffic sites.

Basically the server returns a 304 Not Modified http Response code, if the content wasn't modified. There are lots of ways to determine whether the requested page was modified or not.

For instance, it could be that you store your content in a database, and as such it would be likely that the entry timestamp, would be the ideal solution for the If-Modified-Since header. I would combine it with a hash check of the file, that way you would also avoid problems when you update the site.

Example:
Code:
$fp = fopen($_SERVER["SCRIPT_FILENAME"], "r"); 
$etag = md5(serialize(fstat($fp))); 
fclose($fp); 
header('Etag: '.$etag); 
 
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $SelectS['LTIME'])." GMT");
header("Etag: $etag");

Note that the $SelectS['LTIME'] Variable contains the output from the LTIME field, this is the Last Modified, or the stamp where the entry was last edited. Its a good idea to both include a timestamp for postage, and one showing when the entry was edited last by original poster, and/or admins.

The content is extracted from a select query performed on your database. It would be a good idea to design your site, in a way which makes it possible to only do this once per page request. You shouldn't have to first check the timestamp, and then somewhat further down run another select, to output the content.

As you may or may not know. The Etag header is used to check if the content requested on a given URL, has changed since the last visit. The browser usually caches the result by default, so if the header of a cached page matches that of a requested URL, the server will respond with a 304 Not Modified.


The next part is simply a PHP if then else Situration. I.e.

Code:
if ((@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $SelectS['LTIME']) && ( 
    trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { 
    header("HTTP/1.1 304 Not Modified");
    exit;
}

As such, sites that receive a lot of traffic, could potentially cut their bandwidth usage in nearly half of what they use without the header. That's why its important.

The full code required, excluding the database connection, and raleted queries. Is shown below:
Code:
$fp = fopen($_SERVER["SCRIPT_FILENAME"], "r"); 
$etag = md5(serialize(fstat($fp))); 
fclose($fp); 
header('Etag: '.$etag); 
 
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $SelectS['LTIME'])." GMT");
header("Etag: $etag"); 
 
if ((@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $SelectS['LTIME']) && ( 
    trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { 
    header("HTTP/1.1 304 Not Modified");
    exit;
}

I would place this in somewhat in the top of your script source, before any other headers are sent. You can even make it as an include, just keep in mind that calls to the filesystem might effect server performance.


Finally, if you need an easy way to use the if-modified-since header with your websites frontpage, then simply select the last inserted row in your content table, and use the timestamp of that.
 
Last edited:
MI
Back