Welcome Guest, Not a member yet? Register   Sign In
Issue with Online library from github
#1

I downloaded the library from Github. But there seems to be alot of problem with it. First of the total_users(); method don't really get total users online it just get one and i don't really understand how to implement it with my database. I'd really appreciate if i get and explicit explanation on how to use it.

Thanks.

Find documentation here
https://github.com/bcit-ci/CodeIgniter/w...line-Users

PHP Code:
<?php
/**
Users Online class *
Manages active users *
@package CodeIgniter
@subpackage Libraries
@category Add-Ons
@author Leonardo Monteiro Bersan de Araujo
@link hhttp://codeigniter.com/wiki/Library: Online_Users
*/
class Onlineusers {
 
   public $file "usersonline.tmp";
 
   public $data;
 
   public $ip;
 
   function Onlineusers() {
 
       $CI = & get_instance();
 
       $this->ip $_SERVER['REMOTE_ADDR'];
 
       $this->data unserialize(file_get_contents($this->file));
 
       $aryData $this->data['useronline'];
 
       if (!$this->data) {
 
           $this->data = array();
 
       }
 
       $now time();
 
       $timeout $now 900;

 
       //Removes expired data
 
       foreach ($aryData as $key => $value) {
 
         if ($value['time'] <= $timeout) {
 
           if ($value['username']) {
 
               $this->data['memonline']--;
 
           }
 
           else{
 
               $this->data['guestonline']--;
 
           }
 
           unset ($aryData[$key]);
 
         }
 
       }
 
       
        
//If it's the first hit, add the information to database
 
       if (!isset ($aryData[$this->ip])) {
 
           $aryData[$this->ip]['time'] = time();
 
           $aryData[$this->ip]['uri'] = $_SERVER['REQUEST_URI'];
 
           $username $CI->session->userdata('username');
 
           //$user = $CI->session->userdata('user');
 
           //$username = user('username');
 
           //$id = user('id');
 
           $aryData[$this->ip]['username'] = $username;
 
           //$aryData[$this->ip]['id'] = $id;
 
           if ($username) {
 
             $this->data['memonline']++;
 
           }
 
           else {
 
             $this->data['guestonline']++;
 
           }
 
           $this->data['totalvisit']++;
 
           //Loads the USER_AGENT class if it's not loaded yet
 
           if (!isset ($CI->agent)) {
 
             $CI->load->library('user_agent');
 
             $class_loaded true;
 
           }
 
           if ($CI->agent->is_robot()) {
 
               $aryData[$this->ip]['bot'] = $CI->agent->robot();
 
           } else {
 
               $aryData[$this->ip]['bot'] = false;
 
           }
 
           //Destroys the USER_AGENT class so it can be loaded again on the controller
 
           if ($class_loaded) {
 
               unset($class_loaded$CI->agent);
 
           }
 
       }
 
       else {
 
           $aryData[$this->ip]['time'] = time();
 
           $aryData[$this->ip]['uri'] = $_SERVER['REQUEST_URI'];
 
       }
 
       $this->data['useronline'] = $aryData;
 
       $this->_save();
 
   }
 
   
    
//this function return the total number of online users
 
   function total_users() {
 
       return count($this->data['useronline']);
 
   }
 
   
    
//this function return the total number of online members
 
   function total_mems() {
 
       if ($this->data['memonline']) {
 
           return  $this->data['memonline'];
 
       }
 
       else {
 
           return 0;
 
       }
 
   }
 
   //this function return the total number of online guest
 
   function total_guests() {
 
       if ($this->data['guestonline'] > 0) {
 
           return  $this->data['guestonline'];
 
       }
 
       else {
 
         return 0;
 
       }
 
   }
 
   //this function return the total number of total visit
 
   function total_visit() {
 
       return  $this->data['totalvisit'];
 
   }
 
   
    
//this function return the total number of online robots
 
   function total_robots() {
 
       $i 0;
 
       foreach ($this->data as $value) {
 
           if ($value['is_robot']) {
 
               $i++;
 
           }
 
       }
 
       return $i;
 
   }
 
   //Used to set custom data
 
   function set_data($data false$force_update false) {
 
       if (!is_array($data)) {
 
         return false;
 
       }
 
       $tmp false;
 
     //Used to control if there are changes
 
       foreach ($data as $key => $value) {
 
           if (!isset ($aryData[$this->ip]['data'][$key]) || $force_update) {
 
               $aryData[$this->ip]['data'][$key] = $value;
 
               $tmp true;
 
           }
 
       }
 
       
        
//Check if the user's already have this setting and skips the wiriting file process (saves CPU)
 
       if (!$tmp) {
 
           return false;
 
       }
 
       return $this->_save();
 
   }
 
   
    function get_info
() {
 
       return $this->data;
 
   }
 
   
    
//Save current data into file
 
   function _save() {
 
       $fp fopen($this->file'w');
 
       flock($fpLOCK_EX);
 
       $write fwrite($fpserialize($this->data));
 
       fclose($fp);
 
       return $write;
 
   }

Reply
#2

greetings - disclamer that i could be wrong - but i think that is a third party library that is not supported by codeigniter.
and it looks like its very old - it could even be for codeigniter 1.7 ? like in the example code on the page there is the line
class Blog extends Controller {

anyway - suggest that you first work through the tutorial in the current codeigniter manual.
Reply
#3

(02-11-2016, 01:28 PM)cartalot Wrote: greetings - disclamer that i could be wrong - but i think that is a third party library that is not supported by codeigniter.
and it looks like its very old - it could even be for codeigniter 1.7 ? like in the example code on the page there is the line
class Blog extends Controller {

anyway - suggest that you first work through the tutorial in the current codeigniter manual.

I figured too. Can you suggest alternative library to get the it done. 

Thanks  Smile
Reply
#4

What are your requirements? What do you need to do?
Reply
#5

(This post was last modified: 02-14-2016, 11:50 AM by Rhyno_xD.)

(02-12-2016, 03:53 PM)cartalot Wrote: What are your requirements? What do you need to do?

I need a code to show me online users from database, online guests, and custom online user.
Reply
#6

(This post was last modified: 02-23-2016, 03:15 PM by moshair.)

It is working on CI30x, I used it for days after fixing it, I don't recommend using it, it uses file system not database it will store the data in a file called usersonline.tmp in your CI root, it consumes a lot of server CPU and you will have big problem if you have a lot of visitors.

I wrote Onlineusers.php library works uses the database, but it is integrated with Authme Authentication from dev7studios.com
Reply
#7

(02-23-2016, 02:35 PM)moshair Wrote: It is working on CI30x, I used it for days after fixing it, I don't recommend using it, it uses file system not database it will store the data in a file called usersonline.tmp in your CI root, it consumes a lot of server CPU and you will have big problem if you have a lot of visitors.

I wrote Onlineusers.php library works uses the database, but it is integrated with Authme Authentication from dev7studios.com

Can you share this code please
Reply
#8

Hello Rhyno_xD,

Demo page for (Online users library + AuthmeMax library) + download link on:

http://php-max.com/ci/

Still in development, please leave a comment on that page for any help.
Good luck
Reply




Theme © iAndrew 2016 - Forum software by © MyBB