943,937 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1406
  • PHP RSS
Sep 27th, 2007
0

Help with Last Activity Time

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. require("Connecting_Config.php");
  4. $unm=$_SESSION['user_name'];
  5. $current_date=date("i"); //Only Minutes
  6. $gt_lastactivity="select * from logs where Name='$unm'";
  7. $do_gt_lastactivity=mysql_query($gt_lastactivity,$connect);
  8. $arr=mysql_fetch_array($do_gt_lastactivity);
  9. $last_activity_date=$arr['Last_Activity'];
  10. $yyy=$current_date-$last_activity;
  11. if ($yyy>20)
  12. {
  13. Logout();
  14. }
  15. ?>
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?
Similar Threads
Reputation Points: 44
Solved Threads: 23
Posting Whiz
Pro2000 is offline Offline
350 posts
since Jun 2007
Sep 27th, 2007
0

Re: Help with Last Activity Time

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));
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Sep 27th, 2007
0

Re: Help with Last Activity Time

Quote ...
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 and delete the user name from the available users.
Reputation Points: 44
Solved Threads: 23
Posting Whiz
Pro2000 is offline Offline
350 posts
since Jun 2007
Sep 27th, 2007
0

Re: Help with Last Activity Time

then you will check it with cookies again and if the given time is up, redirect the page the username from availables list.
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: select information from databse
Next Thread in PHP Forum Timeline: php header include on html? (picture gallery)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC