How to check how many users online on the website with php? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to check how many users online on the website with php?

I want to check how many users online on the site but i faced a proplem: I used session so if someone closed the browser without logging out it will still appearing as online user!

14th Mar 2023, 3:41 PM
Hasan Hatem
Hasan Hatem - avatar
1 Answer
+ 3
A commonly used pattern is to keep track of the last activity of each session, by updating a session variable on each request. This way you could determine the rime of the last activity, and based on some threshold that you define yourself, you could classify a user inactive, if they haven't done any activity since eg. 30 minutes. https://www.ma-no.org/en/programming/php/how-to-implement-a-php-session-timeout-on-your-own
14th Mar 2023, 5:17 PM
Tibor Santa
Tibor Santa - avatar