|
|
[Back to list] [Execute]
<?php
// Xorlev (2007)
// elementation@gmail.com
// Constants
define('TIME_PERIOD', 30); // Time period in seconds
define('MAX_VIEWS', 5);
// Initialize session
session_start();
// Record our start time for consistency, as checks could conceivably push the time ahead a second
$time = time();
// Function for callback
function remove_old($logitem) {
global $time;
if (($time - $logitem) > TIME_PERIOD) {
return false;
} else {
return true;
}
}
// Remove < TIME_PERIOD entries
$_SESSION['log'] = @array_filter($_SESSION['log'], 'remove_old');
// Lets add a new entry to the session log
$_SESSION['log'][] = $time;
if (count($_SESSION['log']) > MAX_VIEWS) {
// We need the last key
$keys = array_keys($_SESSION['log']);
// Get rid of that last entry. They didn't see the show
unset($_SESSION['log'][end($keys)]);
// Error code
echo 'Error: You have exceeded the maximum (' . MAX_VIEWS . ') in ' . TIME_PERIOD . ' seconds.';
die();
// Here
}
// On with the show
?>
|
|
|