Javascript popup popping up PHP session?

In an attempt to handle expiration of PHP sessions more elegantly, I introduced the following into my PHP code:

$sessionLifeTimeInSeconds = ini_get ("session.gc_maxlifetime"); echo '<script type="text/javascript">' . "\n" . ' setTimeout (function () {' . "\n" . ' alert ("Your login session will expire in 3 minutes.");' . "\n" . ' }, ' . ($sessionLifeTimeInSeconds - 180) * 1000 . ');' . "\n" . '</script>' . "\n\n"; 

What works. However, now I notice that after clicking the OK button in the javascript warning and no additional activity, the session does not expire when the timeout is reached (the default is 24 minutes in this case).

Should a warning popup extend my session? If so, can this be avoided, and if so, how?

I use Firefox 44.0 on Ubuntu Linux, if at all relevant.

+5
source share
1 answer

The pop-up window does not expand the session, since the session is held by the server for 24 minutes and is distributed only if there is interaction with the server.

Try making a server call through javascript in your javascript function to extend the php session, for example, calling an AJAX for root:

 $sessionLifeTimeInSeconds = ini_get ("session.gc_maxlifetime"); echo '<script type="text/javascript">' . "\n" . ' setTimeout (function () {' . "\n" . ' alert ("Your login session will expire in 3 minutes.");' . ' xhttp.open("GET", "/", true);' . ' xhttp.send()' . "\n" . ' }, ' . ($sessionLifeTimeInSeconds - 180) * 1000 . ');' . "\n" . '</script>' . "\n\n"; 
0
source

Source: https://habr.com/ru/post/1242991/


All Articles