Hello Guys,

I have found this counter, but i want it to refresh the number every 1minute, so for example it says "19" and the end user keeps refreshing the page, he wont see the number changing untill its been 1min.


function randomGen($min, $max)
    // setup our seed
    srand((float) microtime() * 10000000);
    // Generate the number
    $random = rand($min,$max); 
   // Return the number
    return $random;
/*adjust these numbers to display a random number within a range-
make sure the low number is on the left.*/

$random_number = randomGen(10,25);

echo "<br/>There are " .$random_number. " visitors online";


But i am also happy to use this, but i want the number to start from 11


Thank you

Edited by NoID: n/a

7 Years
Discussion Span
Last Post by BeachyUK

The code you've included in your post seems to just generate a random number and display it to the user... i.e. it's not giving real information at all... I would definitely not recommend lying to your userbase (which is effectively what that script does).

In terms of the link you provide, that script would logically need some housekeeping, or your SQL table will just grow and grow (dependent on the size of visitors to your site, that could quickly get out-of-hand).

Perhaps the way to achieve what you're after could be to do a similar script to that which you link to, but the output being to a text file, or single field in a table and cron the script (i.e. a cron'd job that counts the "current" users according to the table, and can do any housekeeping on the table if required). The user loading the page then only needs to trigger a script to write their IP to the table, and to lookup the last count from a summary table. The server effort you are saving here is only in terms of doing a COUNT from the visitor table. It may still be worth doing though.

As a host myself, I'd not want a user to cron something every 1 mins, so I'd probably advise that you get the effort as part of the user triggered script (i.e. when user visitors a page it:
- Adds IP to visitor table
- Looks up last count in a summary table which should contain the count, and the "last updated" info
- If "Last Updated" info shows the count is older than 1 mins (you specified you want an updated each minute), then it triggers an update of the summary table.

Does that make sense?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.