I've been stuck on this for a couple of days now, and I'm really having trouble getting this script to function correctly.
I have a very basic starting script, which outputs a random page of text/html/php every time the page refreshes.
<?php
$pages = array(1 => 'text1-1.php', 2 => 'text1-2.php', 3 => 'text1-3.php', 4 => 'text1- 4.php');
$key = array_rand ( $pages );
include($pages[$key]) ;
?>
My goal is to have a script that only changes the output every 1 or 2 days (or what ever time is specify), so no matter how many times you refresh the page, the output won't change until the timer expires.
I have tried the following pieced together from tips people have given me, but no matter what I try the script always outputs something different, every time the page is refreshed.
I think the problem is the file isn't caching, but I don't understand why.
If there are any other problems you can see, I would be grateful for some pointers. :)
Thank you for any help you can offer. :)
<?php
$pages = array(1 => 'text1-1.php', 2 => 'text1-2.php', 3 => 'text1-3.php', 4 => 'text1- 4.php');
$cachefile = "cache/timer.xml";
$time = $key = null;
$time_expire = 24*60*60;
if(is_file($cachefile)) {
list($time, $key) = explode(' ', file_get_contents($cachefile));
}
if(!$time || time() - $time > $time_expire) {
$key = rand(0,count($pages)-1);
file_put_contents($cachefile, time().' '.$key);
}
include($pages[$key]) ;
?>