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
Share on other sites

You are also adding overhead to each page load by checking for and logging out users on every page load. If you really want to do this, you are best off creating a script to do this, and having it executed using cron runs in the background.

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.