EnexoOnoma
EnexoOnoma

Reputation: 8834

Simple modification to a counter script that adds based on timer than page visiting

Hello my goal is to modify this following script to add +1 based on a timer than on page visiting.

What I mean, the timer must add +1 visitor on every 20 minutes. If it is possible it would be great to add +1 on a random time between 15 to 20 minutes.

Then the result will be present in the page. Here is the code

<?php 

$File = "counter.txt"; //the file
$handle = fopen($File, 'r+') ;
$data = fread($handle, 512) ; //get the number on the counter
$count = $data + 1; //Add 1
print "You are visitor number ".$count; //Prints it on page
fseek($handle, 0) ; //puts the pointer back to the begining 
fwrite($handle, $count) ; //saves it
fclose($handle) ; //close it

?>

Thank you!

Upvotes: 0

Views: 129

Answers (1)

Delan Azabani
Delan Azabani

Reputation: 81492

To do that, you need to have the script running not as part of a page request, i.e. on the command line either with an external task scheduler (like anacron) or have it running all the time, sleeping for the delay time and doing the counting in a loop.

Upvotes: 1

Related Questions