Add a random number every 24 hours
<p>i need a script that automatically add a random number (between 1 and 5) every 24 hours and stores it in a text file, then after 24 hours creates a new random number and adds it to the previous result in the text file, i managed to do something close but still needs a refresh button to take effect, but i want it to automatically do it, so if 1 user visits the page every day, and one visits the page once a month, they should both see the same number (which will be read from the text file).</p>

<p>Here is my code so far:</p>

<pre><code>&lt;?php

$dataFile = "amt.txt";

$date1 = date("H:i:s");
$date2 = date("H:i:s",filemtime("amt.txt"));

$diff = abs(strtotime($date2) - strtotime($date1));


$secs = floor($diff);


if ($diff &lt; 86400) {

    echo "$date1 \n"; 
echo "$date2 \n";
printf($secs);
    exit;
}   

if (!file_exists($dataFile)) {
    $amt = 0;
}
else {
    // Otherwise read the previous value from
    // the file.
    $amt = (int) file_get_contents($dataFile);
}

// Generate the new value...
$Number = rand(1,5);
$total = $amt + $Number;
echo "$". $total ."/-";

// And dump it back into the file.
if (!file_put_contents($dataFile, $total)) {
    // If it fails to write to the fle, you'll 
    // want to know about it...
    echo "Failed to save the new total!";
}



?&gt;
</code></pre>

<p>basically i want to show a fake number of subscribers which logically should increase with time. So i want to update the number on daily basis, then because i am having this on my website as the number of monthly subscribers, so when a user visits the website any time should see the same figure as any other user visitng the website on that exact time. Hope this is clearer now.</p>
