News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1225990396:v:use_geshi-1:v:type-php

Started by SleePy, Nov 06, 2008, 04:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

<?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;
?>
No siggy! :D