Jump to content

15min Auto-Logout Script ISSUE


Swarfega

Recommended Posts

Hey.

 

 

Recently did this to my site:

 

 

1 - Added a new Column to the Users Database using Hour-Minute-Second

2 - New PHP which runs everytime a user Loads a page = Updates the last_activity column

3 - New PHP Which runs everytime a suer Loads a page = Checks for Offline users and marks them as offline

 

 

This works, to some degree. I'm having an issue tho.

 

 

If a user doesn't logon for, lets say, 12 hours or a whole day, the system does not recognize them as having been oflfine that long, because their last saved Activity would still be something like "15:03:52" and because of this the System randomly puts them online when they're not really online.

 

 

I was wondering if anyone has a decent fix for this?

 

 

These are the two PHPs I'm using

 

 

update_timer.php

<?php
session_start();
require_once('config.php');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}

$getdate = date('H:i:s');

$SQL = "UPDATE potatis SET last_activity='".$getdate."' WHERE uid='".$_SESSION['SESS_MEMBER_ID']."'";
mysql_query($SQL) or die(mysql_error());

?>

 

logout_timer.php

 


<?php
require_once('config.php');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}

$getdate = date("H:i:s");
$date = explode(":", $getdate);

$date[0] = $date[0] * 60 * 60;
$date[1] = $date[1] * 60;
$totalsecondsnow = $date[0] + $date[1] + $date[2];


$SQL = "SELECT uid, last_activity FROM potatis";
$RESULT = mysql_query($SQL);

while($row = mysql_fetch_assoc($RESULT)) {
$thendate = explode(":", $row['last_activity']);
$thendate[0] = $thendate[0] * 60 * 60;
$thendate[1] = $thendate[1] * 60;
$totalsecondsthen = $thendate[0] + $thendate[1] + $thendate[2];

$totalsecondsallowed = $totalsecondsthen + 900;

if($totalsecondsnow > $totalsecondsallowed) {
$qry = "UPDATE potatis SET connected='offline' WHERE uid='". $row['uid'] . "'";
mysql_query($qry) or die(mysql_error());
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/272851-15min-auto-logout-script-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.