Jump to content

Sessions | Online Users


Cooper94

Recommended Posts

Is it possible to have a script check every minute to make sure the user is still online?

 

<?php
$inactive = 60;

if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{ 
mysql_query("UPDATE pilots SET online = '0' WHERE callsign = '$_SESSION[username]'");
}}

$_SESSION['timeout'] = time();
mysql_query("UPDATE pilots SET online = '1' WHERE callsign = '$_SESSION[username]'");
?>

 

This does the tick but the client needs to refresh the page to online = 0. Is it possible to have it go to 0 before they refresh? So that when they do refresh the page from being back it will than upate the status to online = 1? Thank you for your time and all your help!

Link to comment
https://forums.phpfreaks.com/topic/184198-sessions-online-users/
Share on other sites

I know this is old but I did setup a cron job for a script that runs and checks to see if the user has reached its limit but it does not work. But if I go to the url the script is located on it will update the database no problem! Below is my script:

 

<?php
include '../includes/db.php'; 
session_start();
$inactive = 60;

if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{ 
mysql_query("UPDATE pilots SET online = '0' WHERE callsign = '$_SESSION[username]'");
}}
?>

 

The $_SESSION['timeout'] is a vairable that that equavilant to time() which is set when the person refreshs any page on the site, I have tested that in an echo and it is outputing a number. Like I said it does work when I go to the script location in my browser. Any help would be great! Thank You

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.