0

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 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?

2
  • 1
    why not save a cookie that expires in 30 minutes, and then you check if that cookie exists? Commented Aug 21, 2011 at 16:54
  • @Simon we are working with some clients that it would be easier to use sessions than cookies, I had already considered that. Commented Aug 21, 2011 at 16:58

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Don't use the load function if you don't want to load content. I suggest a simple $.ajax({ url: "check.php"});
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.