dynDate: dynamic date changer
<?
/*
name: dyndate.php
author: keith beckman
date: 011706
url: http://alphahelical.com/code?dyndate
description: dyndate provides a dynamically-updated "last-modified"
date for use in infrequently-updated web pages. It takes a period,
or the maximum number of days between updates, and a resolution,
or the number of days plus or minus a centre (with the maximum
being the period) to update within.
Upon each load, dyndate will calculate an interval within the range
specified by period and resolution. If the date served is older than
that range allows, the date is updated to the current date. The
traffic of search engine spiders nearly guarantees that a user will
not be the one to "flip the hourglass" as it were, and unwittingly
contributes to the believability of the farce.
To Do:
* Date caching: There's no need to look at the date more than once
a day, so caching the rendered date in a file, and reading from
that file rather than running all the math, if the date has already
been looked up in the last twenty-four hours, should reduce its
already-infinitesimal server load on high-traffic sites.
* Function interface, which would allow a single, centrally-located
dynDate script to work for each page on the site. It's small, but
who wants a dozen copies for each of a dozen periods?
*/
$touchfile = '.dyndate.touchfile';
$period = '60';
// Maximum period in days
$resolution = '8';
// Resolution in days
$dateFormat = 'l, F j, Y';
/* HERE THERE BE DRAGONS */
# $period = $period * 24 * 60 * 60; // Convert period to seconds
// This period function can be used to set the centre point of the blur,
// rather than its maximum.
$period = ($period - $resolution) * 24
* 60
* 60;
// Convert period to seconds
// Also, make sure we never exceed it in the blur function: more intuitive
$resolution = $resolution * 24
* 60
* 60;
// Convert resolution to seconds
$date = filemtime($touchfile);
$today = time();
$blur = mt_rand(0,
$resolution);
$operation = mt_rand(0,1
);
// Blur plus or minus (depending on $operation) the period.
if($operation == 0
) {
$period = $period - $resolution;
}
elseif($operation == 1
) {
$period = $period + $resolution;
}
if($today - $date >
$period) {
$date = $today;
touch($touchfile);
}
echo(date($dateFormat,
$date));
?>
Generated by GNU enscript 1.6.1 and enscriptclean.
dynDate | Download Source | View Source