#11
Here is my mysql version, session version was not working.
[code]
/*
CREATE TABLE `online_users` (
`id` varchar(100) NOT NULL,
`user_id` int(11) DEFAULT NULL,
`time_stamp` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `time` (`time_stamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/

function _check()
{
$this->module('members');
$member = $this->members->_get_member_obj();

if($member) {

$session = session_id();
$time = time();

$count = $this->model->count_where('id', $session, '=', 'id', 'online_users');

if ($count == 0) {
$data = array();
$data['id'] = $session;
$data['user_id'] = $member->id;
$data['time_stamp'] = $time;
$this->model->insert($data, 'online_users');
} else {
$data = array();
$data['time_stamp'] = $time;
$this->model->update($session, $data, 'online_users');
}
}
$this->_delete();
}

function _online_users()
{
$this->_delete();
$sql = "SELECT * FROM online_users";
$sql .= " JOIN members ON members.id = online_users.user_id";
return $this->model->query($sql, 'object');
}

function _delete($back = 300)
{
$time_check = time()-$back;
$sql = "DELETE FROM online_users WHERE time_stamp
#12
Hi frocco,

The db version looks sound, similar logic, missing the complete _delete() method but I get the gist.

How was the session version failing?
#13
I tested the server based version by signing it with a different browser and my admin panel still showed no one logged in.

Not sure what happened to the delete, I did use open and closed code blocks.
#14
Ah OK, the db version is probably more like the Laravel version you started with anyway, as it's persistent no matter which browser you you use or where your user are logging in from.

With the code blocks in this help-bar, it's best to run them through an online HTML entities converter prior to pasting them in your post, as any opening php tags or some other HTML will be stripped