Jump to content

Recommended Posts

Hi all,

 

This may be a very very stupid question

 

I have an AJAX-based site going, with one page refresh, and naturally I use sessions. But the problem is that after x amount of time, the session expires. Which is good, except that on an AJAX based site I can't 'keep the session alive' by going to different pages all the time. even though every 10 minutes i check for messages with a PHP script (one of many) it doesn't see it as activity and as such the session expires.

 

Any suggestions on how i can keep renewing the session every x minutes, or every time a script is executed? Or whether or not i can check if a session has expired and have access to what WAS in the session and reset it again?

 

A friend of mine said something about using time() and the Epoch, which i know about but i dont quite see how it's going to help. It can tell me if a session is about to expire, but then what, how do i 'restart' it while keeping all the values?

 

Any help would be handy. :) :)

Link to comment
https://forums.phpfreaks.com/topic/150842-renewing-a-session/
Share on other sites

Hi there, thanks for the response :)

 

I think you may have misunderstood me, the sessions are being set just fine, and they last, just as expected (i set it to 3600 seconds ... 1 hour) but i want to know if i can keep resetting it every time a script is accessed, thus granting a further 3600 seconds of 'idle time'.

 

At the moment, i start off with

 

session_set_cookie_params(3600);
session_start();

 

and any scripts that launch 'applications' via AJAX just use session_start(); which mostly seems to get ignored.

 

But have no fear, i've decided that for the sake of my sanity and the stupidity of users, i'm going to have infinite sessions. I must just make sure that they cannot be hijacked.

Link to comment
https://forums.phpfreaks.com/topic/150842-renewing-a-session/#findComment-792406
Share on other sites

session_set_cookie_params(3600) only sets the cookie lifetime. That is how long the cookie will be retained when the browser is closed. This has nothing to do with someone having requested a page from your site that started a session and they still have their browser open.

 

What is the URL of your main page and the URL that ajax requests. xxxxx out any sensitive information, like the domain name, but don't change any of the hostname/path parts.

Link to comment
https://forums.phpfreaks.com/topic/150842-renewing-a-session/#findComment-792580
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.