Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71723
Share on other sites

I dont think that is possible.

I am guessing your are looking for a script which tells who is logged in

What you can do is

On every page load, check if a user is logged in, if they are update the MySQL table to say the date and time

then to check who is logged in, check everyone who has action within 10 minutes.
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71725
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71731
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71740
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71751
Share on other sites

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'");
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71758
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/17003-sessions-table/#findComment-71764
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.