简体   繁体   English

Javascript警报弹出窗口是否会扩展PHP会话?

[英]Does a Javascript alert popup extend the PHP session?

In an attempt to handle expiring PHP sessions more gracefully, I have inserted the following in my PHP code: 为了更优雅地处理过期的PHP会话,我在PHP代码中插入了以下内容:

$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";

Which works. 哪个有效。 However, now I notice that after clicking the 'OK' button on the javascript alert and no further activity whatsoever, the session does not expire when the timeout (the default 24 minutes in this case) has been reached. 但是,现在我注意到在单击javascript警报上的“确定”按钮并且没有任何进一步的活动之后,当达到超时(在这种情况下默认为24分钟)时,会话不会过期。

Should the alert popup box extend the session? 警报弹出框是否应该延长会话? If so, can this be avoided and if so, how? 如果是这样,可以避免这种情况,如果是这样,怎么办?

I'm using Firefox 44.0 on Ubuntu Linux, if that's relevant at all. 我在Ubuntu Linux上使用的是Firefox 44.0,如果它完全相关的话。

The popup box does not extend the session because the session is hold by the server for 24 minutes and only extends if there is an interaction with the server. 弹出框不会延长会话,因为会话由服务器保留24分钟,并且仅在与服务器进行交互时才会延伸。

Try to do a server call via javascript in your javascript function to extend the php session, for example an AJAX Call to the root: 尝试在javascript函数中通过javascript进行服务器调用以扩展php会话,例如对根进行AJAX调用:

$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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM