Joomla 3.x - 如何在访客用户的现场显示某个用户

时间:2017-06-16 15:21:40

标签: php joomla joomla3.0

我要做的是向Joomla网站的访客/访问者显示某位成员当前是否已登录。到目前为止我所拥有的是:

    //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.";
    }
}

然而,这不起作用。我有这种方法,只适用于匹配用户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.";
    }

}

但我无法为来宾用户开展工作。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

Joomla用户对象返回当前用户(正在浏览的人)数据。您需要检查会话表的数据。此表存储会话信息。

$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";
}