开发者

Update PHP via Javascript

I have a javascript code that basically displays a box that says that you will be logged out within 60 seconds if you dont click on the link. Now my question is can I use that link with a JavaScript onClick event to somehow update my php code that detects if your session is older than 30 mins.

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    // last request was more than 30 minates ago
    session_destroy();   // destroy session 开发者_C百科data in storage
    session_unset();     // unset $_SESSION variable for the runtime
    header("location:login.php");
}

Short of refreshing the includes.php file is there anything else that I can do to update my $_SESSION['LAST_ACTIVITY'] variable?


You'll have to use ajax

I'd suggest you to use jQuery for that.

$("#link").click(function(){
    $("#result").load('check.php');
});

To update variable, use

$_SESSION['LAST_ACTIVITY'] = time();


you can use session_cache_expire(); and put that before session_start();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜