Golden_Eagle
03-07-2003, 12:12 PM
I have been trying to create a random Font Of The Day part on my site. I have managed to come up with this piece of code and have been told by others that it should work.
$filename = "/path/to/fotd.txt";
$contents = file($filename);
if ($contents['1'] <= (time()+86400)) {
$number=rand(1,12000);
$fileshowid=$number;
$handle = fopen ($filename, "w");
$contents = fwrite ($handle, $number);
$contents = fwrite ($handle, time());
fclose ($handle);
} else {
$number = $contents['0'];
}
The fotd.txt has just 2 lines in and is laid out like this
1
1046960000
1st line is fontid
2nd line is Unix Timestamp
The problem is, if you refresh the page the FOTD changes. I only require it to change every 24 hours. Can anyone help - or am I barking up the wrong tree?
Check it out here (http://www.font-factory.com)
$filename = "/path/to/fotd.txt";
$contents = file($filename);
if ($contents['1'] <= (time()+86400)) {
$number=rand(1,12000);
$fileshowid=$number;
$handle = fopen ($filename, "w");
$contents = fwrite ($handle, $number);
$contents = fwrite ($handle, time());
fclose ($handle);
} else {
$number = $contents['0'];
}
The fotd.txt has just 2 lines in and is laid out like this
1
1046960000
1st line is fontid
2nd line is Unix Timestamp
The problem is, if you refresh the page the FOTD changes. I only require it to change every 24 hours. Can anyone help - or am I barking up the wrong tree?
Check it out here (http://www.font-factory.com)