简体   繁体   English

Joomla 3.x-如何向访客用户显示特定用户在站点上

[英]Joomla 3.x - How to display that certain user is on site to a guest user

What I am trying to do is to display to an guest/visitor to a Joomla site that a certain member is currently logged in or not. 我想做的是向某个访客或访客显示Joomla网站上某个成员当前是否登录。 What I have so far is this: 我到目前为止所拥有的是:

    //First assigned user object to $user variable
$user = & JFactory::getUser();
if($user->guest){
    //Check user id is zero, if it is zero means user not logged in Joomla
    if ($user->id == 638) {
        echo "online.";
    } else {
        echo "offline.";
    }
}

However this does not work. 但是,这不起作用。 I have this method which works only for the person that matches the user id: 我有这种方法仅适用于与用户ID匹配的人:

//First assigned user object to $user variable
$user = & JFactory::getUser();

//Check user id is zero, if it is zero means user not logged in Joomla
if ($user->id == 638) {
    echo "online.";
} else {
    echo "offline.";
    }

}

But I can't make the work for the guest user. 但是我无法为来宾用户完成工作。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Joomla user object return current user's(who is browsing) data. Joomla用户对象返回当前用户(正在浏览)的数据。 You need to check session table's data. 您需要检查会话表的数据。 This table store session info. 该表存储会话信息。

$db     =& JFactory::getDBO();
$db->getQuery(true);
$query  = 'SELECT COUNT(userid) FROM #__session WHERE userid = 638';
$db->setQuery($query);
$loggedin   = $db->loadResult();
if($loggedin){
    echo "online.";
} else {
    echo "offline";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM