I have the following code to count visitors on my PHP site. It works fine on my local development machine using WampServer but when I uploaded my files to my hosting account for
The best (free) way to count visitors is here: http://www.google.com/analytics.
If you want more realtime data, (for instance, currently active users) try: http://www.woopra.com/
If you're set on maintaining who is active on your site with your own code, I'd do so with a "last action" date field in your database on the users table. You will be able to do a PHP equivalent query to SELECT COUNT(id) FROM Users WHERE #{Time.now} > #{15.minutes.ago}
If you want to track anonymous users as well, rather than using the Users table, make a table with the visitor's IP as the identifying field and use the same technique mentioned above.