Welcome Guest, Not a member yet? Register   Sign In
Session expired when computer is in idle
#1

[eluser]rochellecanale[/eluser]
Hello guys. Just need a little help here. Now i am creating my own website and i want to add a functionality that will expire the session when the computer is in idle for 30 minutes. And it will automatically redirect the page for viewing the login form. How can i do that? Please help me guys. Thank you.
#2

[eluser]TheFuzzy0ne[/eluser]
The simplest solution is to simply set your session expiration to 30 minutes, but obviously, you have no way of telling whether or not a user was logged in before or not.

Here's what I do:
Set CodeIgniter sessions to last indefinitely.
When the user logs in, I set the time that their session should expire in the session data.
For each page request, I check that the expiry time hasn't passed. If it has, then the user is logged out and redirected to the login page with a message.
If their session has not expired, I re-set the expiry time.

You can put this functionality into a library, or into a base controller and extend it. It's simple enough.

Hope this helps.
#3

[eluser]rochellecanale[/eluser]
ok thanks at least i have an idea. Thanks again
#4

[eluser]boltsabre[/eluser]
Quote: And it will automatically redirect the page for viewing the login form.
Did you want so that it really does automatically redirect them? So, let's say I'm on a page, leave my computer for 45 minutes, come back, what should I see? The same page, or the login page?

If the latter you'll have to use javascript. You'd want to have a site wide function (so, put it in a file which is called from every page, or whatever tickles your fancy). On page load, it starts a timer for 30 minutes, when that's expired use JS to redirect to your login page. You'd have to put in some even listeners, and each time an event is fired you'd have to reset/restart the timer (event listeners you'd be interested in would be mousemove on the body tag, focus, keypress and perhaps a couple others).

However... I really wouldn't recommend it. What if I fill out a form, and just before I submit it get a knock at the door... I leave the computer, come back and hey, WFT, where has my form gone? Now I have to find it, fill it all out again, etc.

A better idea, for pages with forms, would be to make some kind of modal box appear on the screen alerting them that their session has expired and that they should either copy their form data or login back into the site, in a DIFFERENT browser tab!
#5

[eluser]rochellecanale[/eluser]
Ok thanks sir. The expiration is after the member has logged in. So in every page in my view folder i have to put a JS function that validates the time idle.
#6

[eluser]Otemu[/eluser]
[quote author="rochellecanale" date="1363314976"]Ok thanks sir. The expiration is after the member has logged in. So in every page in my view folder i have to put a JS function that validates the time idle. [/quote]

You can just link to an external js file, instead of adding inline js, if you have a master template page then you could add it to that




Theme © iAndrew 2016 - Forum software by © MyBB