<?php
// We have a cache file?
if (file_exists(dirname(__FILE__) . '/.cache'))
{
// Redirect it.
$file = file_get_contents(dirname(__FILE__) . '/.cache');
if (!empty($file))
header('Location: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $file);
// Now secretly we will unlink it.
if ((time() - filemtime(dirname(__FILE__) . '/.cache') > 3600))
unlink(dirname(__FILE__) . '/.cache');
// Only exit, if we sent the header.
if (!empty($file))
exit;
}
// Find all files.
$files = scandir(dirname(__FILE__));
// Remove bad ones.
foreach ($files as $key => $file)
if (in_array($file, array('.', '..', 'index.php', '.cache')))
unset($files[$key]);
// Sort it.
sort($files);
// Get a key.
$key = rand(0, count($files));
// Sent the user away.
header('Location: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $files[$key]);
// But we still get the cache setup for this.
file_put_contents(dirname(__FILE__) . '/.cache', $files[$key]);
// Good bye.
exit;
?>