Well, okay, but only because you asked so nicely...I know! Please, share the secret...

To summarize, though, I just told my server to redirect any traffic from a .png file to a .php file that can randomize my avatar.
And now the gory details:
For simplicity, ${AV_DIR}/av.png is the address of the randomized avatar, and the source images are in ${AV_DIR}/avatar/.
Code: Select all
From ${AV_DIR}/.htaccess:
AddHandler cgi-script .png
From ${AV_DIR}/avatar/.htaccess:
RemoveHandler .png
From ${AV_DIR}/av.png:
#!/xhbin/php
<?php
//Init
$nTotal = 0;
$fn = explode('/', $_GET['fileName']);
$fn = $fn[count($fn) - 1];
if (strpos($fn,'av.png') == false) {
$fn = "";
}
// Was a filename passed?
if ($fn == "") {
$path = './avatar/';
$dir = opendir($path);
if ($dir !== false) {
while (false !== ($file = readdir($dir))) {
if ((strpos($file,'.png') || strpos($file,'.gif') ||
strpos($file,'.jpg')) && strpos($file,'av.png') === false) {
$img[$nTotal] = $file;
$nTotal++;
}
}
closedir($dir);
}
$now = time();
$nToday = 0;
for ($i = 0; $i < $nTotal; $i++) {
$date[$i] = filemtime($path.$img[$i]);
if ($now - $date[$i] <= 86400) {
$today[$nToday] = $img[$i];
$nToday++;
}
}
$fn = "";
if ($nToday > 0) {
$num = rand(0, $nToday - 1);
$fn = $today[$num];
} elseif ($nTotal > 0) {
$num = rand(0, $nTotal - 1);
$fn = $img[$num];
}
}
if ($fn != "") {
// header("HTTP/1.1 302 Found");
header("Content-Type: image/png");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$fp = fopen($path.$fn, 'r');
while (!feof($fp)) {
echo fread($fp, 8192);
}
fclose($fp);
exit;
}
header("HTTP/1.1 404 Not Found");
header("Content-Type: application/xhtml+xml");
header("Cache-Control: no-cache");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>404 Not Found</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<meta name="robots" content="noindex,noarchive,nofollow" />
</head>
<body>
<h1>404 Not Found</h1>
<p>
A suitable resource has not been found. Unfortunately, there are no avatars
available in this folder. As a result, You are seeing this error page
instead.
</p>
<div>Possible solutions include:<br />
<ul>
<li><a href="javascript:location.href=location.href;">Reload</a>ing this
page</li>
<li><a href="mailto:my@email.address">Email</a>ing me, and begging me to
fix it</li>
<li>Or, just living with these results</li>
</ul>
What you do, then, is up to you</div>
</body>
</html>
I removed my email address from the above code to prevent potential spamming
The line that says "#!/xhbin/php" is needed only because of my server's configuration, and will probably not work on your server. If you are not using that line, the .htaccess file may require "AddHandler application/x-httpd-php .png" instead. Experiment around until it works.
EDIT: Removed dead link, added source code instead.
EDIT: Fixed for use in phpBB