I created a little script to keep the PHP session active even if the user does not refresh the page.
Here is the Javascript I'm using via PHP to keep the session alive:
echo 'setInterval(function(){$.post(\'/refreshTheSession.php\');},90000);';
It works fine, but I've noticed that it will keep calling the refreshTheSession.php
script even if the page is not in focus, which I don't want because it means someone can leave a tab open with that page and keep the session alive indefinitely even if they are on a different tab doing something else.
I only want the session to stay alive if the user is still actively on the page in question.
Is it possible to do that? If so, how can I modify my code above to do that?