Login   Register  
PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Moazam  >  PHP Online Users  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Demo file
Class: PHP Online Users
Keep track of site visitors
Author: By
Last change:
Date: 6 years ago
Size: 1,071 bytes
 

Contents

Class file image Download
<?php
session_start
();
$db_server 'localhost';
$db_name 'onlineusers';
$db_user 'root';
$db_pass '';

$LINK mysql_connect($db_server,$db_user,$db_pass) or die("Can't connect to mysql server");
mysql_select_db($db_name,$LINK) or die("Unknown database");

$CURUSER = array(); //in this example i am holding loggined user data in CURUSER array

/*
Dummy record
$time = (time()+(3600*24*100));
setcookie('user','user 1',$time);
setcookie('user_id',1,$time);
*/

if (isset($_COOKIE['user']) && $_COOKIE['user'] != '' && isset($_COOKIE['user_id']) && is_numeric($_COOKIE['user_id'])){
    
//you may want to validate your user record here
    
$CURUSER['user'] = $_COOKIE['user'];
    
$CURUSER['user_id'] = $_COOKIE['user_id'];
}

require(
"online.class.php");
$ONLINE = new whoIsOnline();
$ONLINE->setSessionTime(1); //5 mins check
$ONLINE->recordUser();
$ONLINE->cleanup(); //it is good to run this function by cron

if(isset($CURUSER['user_id']) && $ONLINE->isOnline($CURUSER['user_id'])) {
    echo 
'User '$CURUSER['user'], ' is online';
}
?>