Woodburn2006 Posted August 9, 2006 Share Posted August 9, 2006 if a user logs in to a website, is there any way of entering the session name into a table, then when they log out it automatically deletes the session record? so that only active logins are in the table?i obviously know how to enter it into the table but i dont know how to automatically delete it.also, is there anyway of doing it so that when the user closes the browser it will delete the entry because most sessions auto delete when the browser is closed?thanks Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2006 Share Posted August 9, 2006 You could have a field in your session table that's called last_click and every time they go to another page it will be updated like this: [code]mysql_query("UPDATE sessions SET last_click='".time()."' WHERE id='{$_SESSION['id']}' LIMIT 1");[/code] Then you could check like this if they have been inactive for a long time: [code]$query = mysql_query("SELECT * FROM sessions WHERE id='{$_SESSION['id']}'");$data = mysql_fetch_assoc($query);if($data['last_click']+(60*30) < time()){ mysql_query("DELETE FROM sessions WHERE id='{$_SESSION['id']}'"); unset($_SESSION['id']);}else { // they are still logged in}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71723 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 I dont think that is possible.I am guessing your are looking for a script which tells who is logged inWhat you can do isOn every page load, check if a user is logged in, if they are update the MySQL table to say the date and timethen to check who is logged in, check everyone who has action within 10 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71725 Share on other sites More sharing options...
Woodburn2006 Posted August 9, 2006 Author Share Posted August 9, 2006 if the user has closed the bowser the session would be deleted and if they try to log in again then they would have to log in again anyway. but what i want is an active users list. but if i used the last_click method then the users record would not be deleted if the browser was closed. so how would i do it so that the record is deleted after an inactive period?if that makes any sense at all Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71731 Share on other sites More sharing options...
GingerRobot Posted August 9, 2006 Share Posted August 9, 2006 As was posted, you have a field that contains a timestamp of when they last clicked something. Then where ever you want to show the users online, you only select those where they last clicked in, say, the last 5 minutes.There is no need to delete anything at all. Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71740 Share on other sites More sharing options...
Woodburn2006 Posted August 9, 2006 Author Share Posted August 9, 2006 ok thanks, how would i select just the last 5 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71744 Share on other sites More sharing options...
d_barszczak Posted August 9, 2006 Share Posted August 9, 2006 This is somthing i have used in the past that is checked every time a user clicks on a link.[code] function update() { $expire = date("U")-60*5; // 5 is the number of minute until expiry. $query = "DELETE FROM sessions WHERE time < '$expire'"; mysql_connect(host, user, pass); $report = mysql_query($query) or die(mysql_error()); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71751 Share on other sites More sharing options...
GingerRobot Posted August 9, 2006 Share Posted August 9, 2006 What i would do is have a field on my user table called last active of something. Then, as i say, i would insert a unix timestamp on each click...$time = time();mysq_query("UPDATE `table` SET `lastactive`='$time' WHERE....")then, on the users online page:$now = time();$fiveminsago = $now - 5*60;$sql = mysql_query("SELECT * FROM `table` WHERE `lastactive`>'$fiveminsago'"); Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71758 Share on other sites More sharing options...
d_barszczak Posted August 9, 2006 Share Posted August 9, 2006 Thats actually better than the way i did it as i had to have a users table and a sessions table wheras you could just search your users table for the last sign of activity not having to worry about deleting sessions and creating them.Just update the last active field.If there's a long way to do something guarunteed ill find it. Quote Link to comment https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.