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

1

Friends, is there any 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 is not. Just know even something like:

"xx users online right now".

Also does not need to be every second, hehehe, but type, every 1 minute or the best average between time and non-overhead of the server.

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

Any help is valid! Many thanks!

    
asked by anonymous 07.01.2018 / 02:23

1 answer

3

Making an online user counter on the site, however simple it may be, is a task with a certain level of complexity. In addition to having to do a somewhat laborious programming in JavaScript synchronization with PHP and using 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 try something new or more robust then I suggest using Supercounters . It is a free webservice and does not need to register. Just insert into 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 accesses: user's country, access origin (referer), access number per day, the time of access, the user's OS, screen resolution, browser among others.

    
07.01.2018 / 13:30