Simple script to know how many users are online on the site?

Asked

Viewed 3,737 times

1

Friends, is there a simple script in php (or some other solution for linux php/mysql server) to know how many users are online on the site? I read that websocket is good for chats. In my case, it’s not chat or anything complex no. Just know even something like:

"xx users online at this time".

Also doesn’t need to be every second, hehehe, but like, every 1 minute or the best average between time and no-overhead server.

This issue of not overloading the server with requests is important. I wanted to know if you have any simple solution that requires as little of the server and data transfer as possible (I’m using shared hosting for now). The expectation is to already have a script that can meet in the future a huge demand of visitors at the same time without overloading the server (when it comes to this, I already hope to be with dedicated server).

Any help is valid! Thank you very much!

  • Has this tutorial which can assist. Each new visit, this code stores visitor data and removes "old" records. Then it captures the total using the "sql itself"

1 answer

3

Making an online user counter on the site, however simple, is a task with a certain level of complexity. Besides having to do a busy programming in Javascript sync with PHP and use database, you will have to do IP control, know when a user entered or left the site etc.

If you want an easy solution to then try something own or more robust, I suggest using the Supercounters. It is a free webservice and does not need to register. Just enter in your site a small code generated in the service, something like this:

<!-- BEGIN: Powered by Supercounters.com -->
<center>
<script type="text/javascript" src="//widget.supercounters.com/ssl/online_t.js"></script>
<script type="text/javascript">sc_online_t(1467207,"Users Online","170ddb");</script>
<br><noscript><a href="http://www.supercounters.com/">Free Users Online Counter</a></noscript>
</center>
<!-- END: Powered by Supercounters.com -->

This code will show how many users are online, and also provides a link where you have a report on the accesses: user’s country, origin of the access (referer), access number per day, time of access, user OS, screen resolution, browser (browser) among others.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.