Junior Spellweaver
- Joined
- Aug 25, 2006
- Messages
- 124
- Reaction score
- 24
Groups are easy but i will fist create a good basic CMS so...
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature currently requires accessing the site using the built-in Safari browser.
I really like this project good, I like your code but I think you over-do things a little too much, anyways that's just you.
Good luck!
Nice, Simple! i like it!
<?php
/**
* Kill direct script access
*/
if (!defined('BASEPATH')) exit('No direct script access allowed');
class CLOUD_Online_users
{
var $CLOUD;
var $file = "usersonline.tmp";
var $data;
var $ip;
/**
* Constructor to load the online user data
*/
public function __construct()
{
$CLOUD =& get_instance();
$this->ip=$_SERVER['REMOTE_ADDR'];
$this->data = @unserialize(file_get_contents($this->file));
if(!$this->data)
{
$this->data=array();
}
$timeout = time()-120;
//First time its loaded
if(!isset($this->data[$this->ip]))
{
$this->data[$this->ip]['time'] = time();
$this->data[$this->ip]['uri'] = $_SERVER['REQUEST_URI'];
//Check if agent is loaded
if(!isset($CLOUD->user_agent))
{
$CLOUD->load->library('user_agent');
$class_loaded = true;
}
//Check robot
if($CLOUD->user_agent->is_robot())
{
$this->data[$this->ip]['bot'] = $CLOUD->user_agent->robot();
} else
{
$this->data[$this->ip]['bot'] = false;
}
if($class_loaded)
{
unset($class_loaded, $CLOUD->user_agent);
}
}
else
{
$this->data[$this->ip]['time'] = time();
$this->data[$this->ip]['uri'] = $_SERVER['REQUEST_URI'];
}
//Remove all the expired dates
foreach($this->data as $key => $value)
{
if($value['time'] <= $timeout)
{
unset($this->data[$key]);
}
}
$this->_save();
}
/**
* Get the total users
*/
public function total_users(){
return count($this->data);
}
/**
* Get the total robots
*/
public function total_robots()
{
$i=0;
foreach($this->data as $value)
{
if($value['is_robot']) $i++;
}
return $i;
}
/**
* Save the data to a file
*/
private function _save()
{
$fp = fopen($this->file,'w');
flock($fp, LOCK_EX);
$write = fwrite($fp, serialize($this->data));
fclose($fp);
return $write;
}
}
?>
Online users done (untested)
It's not CodeIgniter.