1

I am setting up a online test platform using php. The problem is with the longer tests having a time of over 60 minutes. In my system a user logs in and takes the tests. Often when the user submits the test answer, he finds that he has been logged out.

It seems that the session id is being destroyed due to idle systems of the users. How to attend the issue?

I do not want to send the variables to garbage after this time, rather I want to make sure that they are not sent to garbage within this time.

soumyajyoti
  • 79
  • 1
  • 13
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Umar Majeed Jan 11 '18 at 07:08
  • The problem is how to increase the time after which the SESSION variables are sent to garbage – soumyajyoti Jan 11 '18 at 07:09
  • I do not want to send the variables to garbage after this time, rather I want to make sure that they are not sent to garbage within this time. – soumyajyoti Jan 11 '18 at 07:11

2 Answers2

4

I guess you can send an ajax call to the server every few minutes to keep the connection.

This way the sesseion of the user will not expire untill the test answers are sumbitted!

function stayAlive(){
$.ajax({
   url: 'theURL',
   type: 'post',
   data: {'can also send data'},
   success: function(){ /* now you are sure the connection is there */ }
});
setTimeout(stayAlive, 60000); // make the call every minute
}

stayAlive();
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
  • That seems like a good idea, but is there any possibility of system issues? – soumyajyoti Jan 11 '18 at 07:15
  • well the only matter is that you get disconnected from the server and reconnect after your session expires. Else, it works fine as you send this call every few minutes! – M Reza Saberi Jan 11 '18 at 07:18
  • A clever idea,instead of call an aJax every minute, you may just call it every half of session time out timer and only while user actively. – Võ Minh Jun 05 '20 at 19:46
1

// try this.

ini_set('session.gc_maxlifetime', 10800);    # 3 hours
session_set_cookie_params(10800);

or

https://prajapatinilesh.wordpress.com/2009/01/14/manually-set-php-session-timeout-php-session/

Nimesh Patel
  • 796
  • 1
  • 7
  • 23