Another alternative might be to use MySQL + an Apache Crontab to control what IPs can access content at whatever times.
I use similar scripting on my own sites. In this case I've compiled a script that will deliver content (the movie), based on the last access time of your IP address, which is stored in a MySQL table.
If the current time, minus 24 hours, turns up greater then your last access time, the database row containing your IP will be deleted. This would mean you could watch your movie again, which inturn, will make a new row with your IP, and start the process all over again.
Here's what you do:
viewer.php - Public movie viewer.
cleartime.php - Hidden script activated by Crontab.
movie_iplist - MySQL table; contains columns "ipAddress" (varchar=15) and "accessTime" (int=15).
Crontab Entry (executes every hour) - 0 php /path/to/cleartime.php >> /dev/null
First, the viewer:
<?php
// --------------------
// viewer.php
// --------------------
// Get current time (seconds since epoch).
$currentTime = time();
// Connect to MySQL + select database
mysql_connect("localhost","username","password"); mysql_select_db("my_database");
// Get an associative array of any row that holds your IP address.
// If nothing is found, return an empty array.
$confirm = mysql_fetch_assoc(mysql_query("SELECT accessTime FROM movie_iplist WHERE ipAddress = '".$_SERVER["REMOTE_ADDR"]."';"));
// Check if the search found anything.
if ($confirm["accessTime"]=="") {
// Did not find an address. You are able to view movie.
echo "I CAN VIEW THE MOVIE! YAY!<br><br>You can only view this movie once!";
// At end of script, insert IP address + Time into MySQL.
mysql_query("INSERT INTO movie_iplist (ipAddress,accessTime) VALUES ('".$_SERVER["REMOTE_ADDR"]."','".$currentTime."');") or die ("Critical Error!");
} else {
// Found your IP address. You cannot view the movie!
echo "ACK! I CAN'T VIEW THE MOVIE! XP<br><br>";
// Print approximate time left until movie viewable again.
$timeleft = (($confirm["accessTime"]+86400)-$currentTime);
$hours = floor($timeleft/3600);
if ($hours>0) {echo "Can view the movie in <b>".$hours." hour(s)</b>.";}
else {echo "Can view the movie in <b>less than an hour</b>.";}
}
?>
Next, the automated script:
<?php
// --------------------
// cleartime.php
// --------------------
// Get current time (seconds since epoch),
// minus 24 hours, plus 60 seconds of leeway.
$currentTime = time()-86400+60;
// Connect to MySQL + select database
mysql_connect("localhost","username","password"); mysql_select_db("my_database");
// Search + Delete all entries, where the column "accessTime"
// presents a number less than the modified current time.
mysql_query("DELETE FROM movie_iplist WHERE accessTime < ".$currentTime.";");
?>
And there you have it, in a nutshell.
I hope this helps. 😃