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

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.