Jump to content

monitoring loggin time


PC Nerd

Recommended Posts

hi guys

 

ive seen that part in the header of this forum when your logged in, and it tells you how much time youve spent online and active.....

 

im wondering how to do this.

 

im using cookies, with an expire time of 30 minutes, BUT people might just not loggout, and the timout is to check that

 

how can i loggout people...., or is there a better way of running the loggin

 

 

i know its very open question, but im just looking for a starting point and pointer.

 

 

thanks guys

Link to comment
Share on other sites

Ok. You have a table like this:

 

user_sessions

=============

sid <-- unique id

s_last_activity <-- integer holding a UNIX timestamp

s_user <-- could be the user id or username

 

Now each time a user goes to a new page on your site you could run this:

mysql_query("UPDATE user_sessions SET s_last_activity='".time()."' WHERE s_user='{$user_id}' LIMIT 1");

 

Then to check if a user has been active in the last 15 minutes you'd do this:

<?php
$result = mysql_query("SELECT * user_sessions WHERE s_user='{$user_id}' LIMIT 1");
if(mysql_num_rows($result) <= 0)
{
echo "No session exists. Not logged in";
}
else {
$session_info = mysql_fetch_assoc($result);
if($session_info['s_last_activity'] >= strtotime("-15 minutes"))
{
	echo "Has been active within the last 15 minutes. Is logged in.";
}
else {
	echo "Has not been active within the last 15 minutes. Not logged in.";
}
}
?>

 

If the user logs out then delete its session in the database.

Link to comment
Share on other sites

lol, i downloaded SMF and looked at the code, and couldnt read the firts statement.

 

its not designed well at all, in terms of readability..... all the code is simply in 3 or 4 lines, for the main mpage alone.........

 

so i couldnt read it

 

 

ive also looked at phpbb, but its the same

 

 

ive also looked at joomla, and am looking at moodle if it has that function...

 

 

anything elsed i should look at

 

 

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.