954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with Last Activity Time

Peace, I wrote a PHP File Contains a login form, If the user logs in a field will be inserted into the MySQL DataBase, So I want to make an automatic logout after 20 minutes idle.
I wrote:

<?php
session_start();
require("Connecting_Config.php");
$unm=$_SESSION['user_name'];
$current_date=date("i"); //Only Minutes
$gt_lastactivity="select * from logs where Name='$unm'";
$do_gt_lastactivity=mysql_query($gt_lastactivity,$connect);
$arr=mysql_fetch_array($do_gt_lastactivity);
$last_activity_date=$arr['Last_Activity'];
$yyy=$current_date-$last_activity;
if ($yyy>20)
{
          Logout();
}
?>

I tried that and I encountered an error which does a logout to the user if he starts another hour.. Ex: Last_Activity= 59th Minute If he does a refresh in the 1st minute in the next hour it will logout, Who knows how to do that?

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

try cookies. that might help you. this example from O'Reilly's Learning PHP5 (free: chapter 8)


// The cookie expires one hour from now
setcookie('short-userid','ralph',time( ) + 60*60);
// The cookie expires one day from now
setcookie('longer-userid','ralph',time( ) + 60*60*24);
// The cookie expires at noon on October 1, 2006
setcookie('much-longer-userid','ralph',mktime(12,0,0,10,1,2006));

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 
try cookies. that might help you.


Sorry but I know this... I created a menu shows the available users, It gets the names from the mysql database, I need to make it when the user expires 20 minutes it will logout anddelete the user name from the available users.

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

then you will check it with cookies again and if the given time is up, redirect the page the username from availables list.

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You