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?

Member Avatar for fatihpiristine

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));

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.

Member Avatar for fatihpiristine

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.