Jump to content

15min-Expiration Logout Script


Swarfega

Recommended Posts

Hey.

 

 

I've made a script that would auto-logout users have they not been active for 15min, but it seems to not be working properly.. I've included these two files in ALL my php's that display data, so that each and every single user contributes to the Currently-Online-Members script whenever they click one of the links.

 

 

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 > $totalsecondsthen) {
$qry = "UPDATE potatis SET connected='offline' WHERE uid='". $row['uid'] . "'";
mysql_query($qry) or die(mysql_error());
} else {
$qry = "UPDATE potatis SET connected='online' WHERE uid='". $row['uid'] . "'";
mysql_query($qry) or die(mysql_error());
}
}
?>

 

 

But it does not seem to work properly.. One person signed on at 13:53 my time, the time when I checked the database, her last_activity was 13:53:43 or something, and the current time was 13:55:23, yet it still showed her being offline, is that not just very wrong?

 

 

Where did I go wrong in the script to make that happen?

 

 

Edit: It does however not put MY user as Offline when I click on a link, my last_activity was 14:01

Edited by Swarfega
Link to comment
Share on other sites

if($totalsecondsnow > $totalsecondsthen) {

 

Shouldn't that be...

if($totalsecondsnow > $totalsecondsallowed) {

 

The way you have it now is like saying, if the current time is greater than their last activity, log them off. Although I'm not even sure the way above will still work

Edited by SocialCloud
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.