Welcome Guest, Not a member yet? Register   Sign In
how do i display users as online when they login and as offline when they logout?
#1

[eluser]Unknown[/eluser]
can any help me suddenly,how to display users as online when they login and as offline when they logout?
#2

[eluser]glemigh[/eluser]
Well I guess it depends on what auth lib you are using, but some variation of this might be what you are looking for.

I have something like this as part of my top menu on some of my projects.

Code:
<?
if ($this->dx_auth->is_logged_in()) {
    ?&gt;<li><a href="&lt;? echo site_url(">Logout</a></li>&lt;?
} else {
    ?&gt;<li><a href="&lt;? echo site_url(">Login</a></li>&lt;?
}
?&gt;

For some reason the pasted example is having parts stripped out, but you should get the idea.

George
#3

[eluser]Zeeshan Rasool[/eluser]
you have to create a function which checks your status on each page or in header which included in your site, So that if the users are online show them logout link and vice versa:
#4

[eluser]BrianDHall[/eluser]
If you are doing all the auth and such yourself, you'll want to start using a "last_accessed" variable in your user information in your database. Update it every time a person visits a page.

Then when you want to see who is logged in, do a query to your database and pull everyone as logged in who is not explicitly logged out (make that a variable for your users if you want, or just ignore explicit log outs entirely) or who's last accessed is older than a certain threshold, like 15 minutes or whatever.

The reason for using this last_accessed concept is people often don't click 'logout', they just close their browser or empty their cache. So to avoid having people logged in forever, you'll need to use something like this basic concept.
#5

[eluser]Unknown[/eluser]
okk, thanx i will try it out
#6

[eluser]InsiteFX[/eluser]
Here for everyone.

Code:
#
#  dbtables.sql
#
#  Simplifies the task of creating all the database tables
#  used by the login system.
#
#  Can be run from command prompt by typing:
#
#  mysql -u yourusername -D yourdatabasename < dbtables.sql
#
#  That's with dbtables.sql in the mysql bin directory, but
#  you can just include the path to dbtables.sql and that's
#  fine too.
#
#  Written by:
#  Last Updated:
#

#
# Table structure for ci_sessions
#
DROP TABLE IF EXISTS ci_sessions;

CREATE TABLE IF NOT EXISTS `ci_sessions` (
  `session_id` varchar(40) DEFAULT '0' NOT NULL,
  `ip_address` varchar(16) DEFAULT '0' NOT NULL,
  `user_agent` varchar(50) NOT NULL,
  `last_activity` int(10) unsigned DEFAULT 0 NOT NULL,
  `user_data` text NOT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


#
# Table structure for table groups

#
DROP TABLE IF EXISTS groups;

CREATE TABLE IF NOT EXISTS `groups` (
  `group_id` int(11) NOT NULL DEFAULT '0',
  `title` varchar(20) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY  (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


#
#  Table structure for users table
#
DROP TABLE IF EXISTS users;

CREATE TABLE `users` (
  `username` varchar(40),
  `password` varchar(32),
  `userid` varchar(32),
  `userlevel` tinyint(1) unsigned NOT NULL,
  `email` varchar(255),
  `timestamp` int(11) unsigned NOT NULL,
  `group_id` int(11) NOT NULL default '0',
  `identifier` varchar(255) NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


#
#  Table structure for active_users table
#
DROP TABLE IF EXISTS active_users;

CREATE TABLE `fx_active_users` (
  `username` varchar(40),
  `timestamp` int(11) unsigned NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


#
#  Table structure for active_guests table
#
DROP TABLE IF EXISTS active_guests;

CREATE TABLE `active_guests` (
  `ip` varchar(15),
  `timestamp` int(11) unsigned NOT NULL,
  PRIMARY KEY (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


#
#  Table structure for banned_users table
#
DROP TABLE IF EXISTS banned_users;

CREATE TABLE `banned_users` (
  `ip` varchar(15),
  `username` varchar(40),
  `timestamp` int(11) unsigned NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Enjoy
InsiteFX
#7

[eluser]basicstudent[/eluser]
Hi
i change your idea for Online status view for all users...
when a user login in system the field "ONline_Status" update to "1".
and when logut this field change to "0", but this idea and code works for 1 users and other user when logout without ONline_Status change.
Code:
function logout()
{
//online status change field
$conditions = array('users.user_status' => '1');
$query = $this->user_model->getUsers($conditions);


if($query->num_rows() > 0)
{
$row = $query->row();
// update the last activity in the users table
$updateData = array();
$updateData['Online_Status'] = "0";
//$updateData['last_activity'] = get_est_time();

//Get Activation Key
$activation_key = $row->id;
// update process for users table
$this->user_model->updateUser(array('id'=>$row->id),$updateData);
}
$this->auth_model->clearUserSession();
$this->session->set_flashdata('flash_message', $this->common_model->flash_message('success',$this->lang->line('logout_success')));
$this->auth_model->clearUserCookie(array('username','password'));
$this->auth_model->clearUserCookie(array('user_name','user_password'));


redirect('home');

}

Can you help me please?
Thank you
More info : i used localhost.
i think this problem from session or cookies!!!!!




Theme © iAndrew 2016 - Forum software by © MyBB