Jump to content

How to expire login if inactive


dhimok

Recommended Posts

im having the same sort of thing......

 

 

http://www.phpfreaks.com/forums/index.php/topic,135061.0.html

 

 

but what i do is use cookies and store the login length. ( in and the out)  so that if somone hasnt logged out within x minutes ,then it defult loggs them out, and stors login length as only 5 minutes, not 20 minutes eg.

 

this "entices" the user to logout correctly

 

 

gd luck

Link to comment
Share on other sites

<?php
session_start();

// note you must set $_SESSION['time'] on your own when the user logins as something like
// time()+3600; expires in one hour
if ($_SESSION['time'] > time()) 
    session_destroy();
?>

Link to comment
Share on other sites

You would either need to have the session data stored in a db with lastactivity as a time field and use a cron job or setup some code to run at the top of a page anytime it is called and check the database session lastactivity and if it is past 20 minutes delete that hash from the DB so the next time the person loads the page check to see if the session still exists if not prompt them to login again.

Link to comment
Share on other sites

well thats where it gets complicated.

 

ill be doing this sson with my site, but at the begining of every page you write a page request log to the database.  fields = request_id, user_id, time, page_name

 

what you do is search the records for User_Id = $User_Id, and time.  find the most recent request ( via time )  and say if it was more than 20 minutes ago, then theyre inactive, and do your logout thing.

 

 

its requires almost a new start.  or at least a new version

 

 

 

 

 

 

please note that i may be completely wrong, and there may be a really easy fool proof way of doing it that i dont know if.......

 

either way, good luck.  ill folliw this thred becauase ill be using it soon.

 

Link to comment
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.