This problem is more complicated than it seems on the surface.
You need to consider session behavior at three different levels:
Php
For PHP, you need to set the session timeout to what you limit. Here is a sample code from php.net :
<?php session_cache_limiter('private'); session_cache_expire(30); session_start(); ?>
Database
It looks like you need to keep track of how many sessions are active so you can apply your license. Since you are in PHP, you need to do this at the database level. Each request could write a "last request time" for the user ( UPDATE users SET last_access=NOW() WHERE user_id=? ), And then you can assume that the active sessions are the ones that were in the last 30 minutes.
Instead of "last access time", you can try to keep track of active sessions, again in the database. I'm not quite sure how this is best done in PHP. I think you can embed PHP session deletion code. I believe that you can call the function when the session expires, but I did not.
Browser
You can use Javascript polling, but this is not necessary if you have a server side timeout. Consider cases where the user disables Javascript, or you have a Javascript error that causes the script to stop working.
We have a very intensive Ajax site, so Javascript is important. A timeout can be detected when a user does something harmless, like opening a panel on a page. I wrote my recent experience here.
source share