get online user list and remove unactive user from list

7 replies
Hello

I am try to make function how get currently online user on my website...
I am saving user_id in table but i am facing one problem when i close my browser without logout my system still showing me login because my user_id is store in DB.

how can i know that the user is actually online means how can i get session is set or destroy.

or if you can best to get online user please tell me.

you can see get my website links from my signature and you can find login user below footer

Regards
#list #online #remove #unactive #user
  • Profile picture of the author jwhitworth
    What language/database?
    {{ DiscussionBoard.errors[7173508].message }}
    • Profile picture of the author lovefax89
      Originally Posted by jwhitworth View Post

      What language/database?
      I am using php and mysql
      {{ DiscussionBoard.errors[7178753].message }}
  • Profile picture of the author dwoods
    You would need to add a "last_activity" column to your database, and update it each time a user does an action (such as loads another page on your site), and then only select your count of "online users" who have an "last_activity" of sometime in the past 10 or 15 minutes.
    {{ DiscussionBoard.errors[7174396].message }}
    • Profile picture of the author lovefax89
      Originally Posted by dwoods View Post

      You would need to add a "last_activity" column to your database, and update it each time a user does an action (such as loads another page on your site), and then only select your count of "online users" who have an "last_activity" of sometime in the past 10 or 15 minutes.
      thanks for your help..now i can do tihs
      {{ DiscussionBoard.errors[7178767].message }}
  • Profile picture of the author Ttrain
    you could also track your current users using getclicky.com just add the code they give you to your footer and your good to go. I think they track up to a 100,000 users at one time. Don't quote me on that though.
    {{ DiscussionBoard.errors[7175686].message }}
  • Profile picture of the author oliviacis
    Originally Posted by lovefax89 View Post

    Hello

    I am try to make function how get currently online user on my website...
    I am saving user_id in table but i am facing one problem when i close my browser without logout my system still showing me login because my user_id is store in DB.

    how can i know that the user is actually online means how can i get session is set or destroy.

    or if you can best to get online user please tell me.

    you can see get my website links from my signature and you can find login user below footer

    Regards
    which language are you using?
    {{ DiscussionBoard.errors[7176139].message }}
  • Profile picture of the author raferti
    --Create My Sql Table ---

    CREATE TABLE IF NOT EXISTS `sessions` (
    `id` int(11) NOT NULL auto_increment,
    `id_session` varchar(256) NOT NULL,
    `up_date` datetime NOT NULL,
    `user` varchar(40) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    ---counter.php ---

    $id_session=session_id();
    $ro=mysql_query("SELECT * FROM sessions WHERE id_session ='".$id_session."'");
    if($ro) {
    if(mysql_num_rows($ro)>0) {
    $upd=mysql_query("UPDATE sessions SET up_date=NOW(), user='".$_SESSION['username']."' WHERE id_session ='".$id_session."'");
    }
    else {
    $into=mysql_query("INSERT INTO sessions (id_session, up_date, user) VALUES ('".$id_session."',NOW(),'".$_SESSION['username']."')");
    }
    }
    $del=mysql_query("DELETE FROM sessions WHERE up_date<NOW()-INTERVAL '15' MINUTE");
    function CountOnlineUsers($ifguest){
    $q=mysql_query("SELECT COUNT(*)FROM sessions WHERE user".$ifguest);
    if(mysql_num_rows($q)>0) {
    return mysql_result($q,0);
    }
    }
    $lang_stat=array(
    'online_all'=>'Онлайн всего: ',
    'online_guest'=>'Гостей: ',
    'online_user'=>'Пользователей: '
    );


    ---online.php

    $guests=CountOnlineUsers("=''");
    $users=CountOnlineUsers("!=''");
    $all=$guests+$users;
    echo $lang_stat['online_all'].$all."<br/>";
    echo $lang_stat['online_guest'].$guests."<br/>";
    echo $lang_stat['online_user'].$users."<br/>";
    {{ DiscussionBoard.errors[7181730].message }}

Trending Topics