• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Users online

Jake Bunce

XenForo moderator
Staff member
#2
Since you have access to the XenForo API with that addon you can use code similar to the index page:

XenForo_ControllerPublic_Index::_getSessionActivityList

Code:
	protected function _getSessionActivityList()
	{
		$visitor = XenForo_Visitor::getInstance();

		$sessionModel = $this->getModelFromCache('XenForo_Model_Session');

		return $sessionModel->getSessionActivityQuickList(
			$visitor->toArray(),
			array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
			($visitor['user_id'] ? $visitor->toArray() : null)
		);

	}
The session model is what you need to retrieve session information.
 

Zephyr

Well-known member
#3
Hello Jake :)

I have this :
PHP:
<?php
    public function userOnlineAction()
    {
 
        $sessionModel = \XenForo_Model::create('XenForo_Model_Session');
        $userOnline = $sessionModel->getSessionActivityQuickList(array(), array());
 
        return $this->render('KynaBoxBundle:Box:MembresEnLigne.html.twig', array('userOnline' => $userOnline));
    }
This is similar ?
Whit this code, I have a list of users online.



Your code does the same thing?

----------------------------------------------------------------

When I visited the forum:
Site stats: 1 user online.
Forum stats: 1 user online.

When I visited the site (without visiting the forum for a while):
Site stats: 0 user online.
Forum stats: 0 user online.

Site => 0 and not 1 visitor :/
Should be that people who are on my site are taken into account in the stats.

And for login user, it's Login model ?
I can not find the method to connect or even veriffier password and start a session.

Thanks.
 

Zephyr

Well-known member
#5
I already have it, my complete code:

PHP:
<?php
 
namespace Kyna\XenforoBundle\Service;
 
/**
* Connexion à la base de donnée Xenforo.
*/
class XenforoIntegration
{
    public function xenforoConnect()
    {
        define('XF_ROOT', '/wamp/www/Project/forums'); // set this (absolute path)!
        define('TIMENOW', time());
 
        require_once(XF_ROOT . '/library/XenForo/Autoloader.php');
 
        \XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT . '/library');
 
        \XenForo_Application::initialize(XF_ROOT . '/library', XF_ROOT);
        \XenForo_Application::set('page_start_time', TIMENOW);
        \XenForo_Application::disablePhpErrorHandler();
        \XenForo_Application::setDebugMode(false);
 
        \XenForo_Session::startPublicSession();
 
        // \$userModel = XenForo_Model::create('XenForo_Model_User');
        // \$userinfo = $userModel->getFullUserById($visitor->getUserId());
 
        // \XenForo_Session::startPublicSession(new \Zend_Controller_Request_Http);
 
        restore_error_handler();
        restore_exception_handler();
    }
}
 
$xenforoIntegration = new XenforoIntegration;
return $xenforoIntegration->xenforoConnect();
I have my XenForo session on my website but the problem does not come from there..
I can not make myself understood in English, I'll try with pictures ^^

My website (use xenforo session) :



My forum :


Now simulate the arrival of a visitor on the forum.
The counter is updated :





Counter site = 1 visitor, forum 1 visitor. Here no problem, everything works fine ;)
But here's another case :




Now simulate the arrival of a visitor on the site.




Problem: Counters remain at 0.
The site does not send data to the db, XenForo is not informed of visits on the site and does not take into account users online thereof and this is what I'm trying to fix :)

visitor => forum => db (UserOnline is update).
visitor => site => db (UserOnline is not update).

Result:
visitor => site/forum => db (getUserOnline is OK but only users who are connected to the forum are included in the user online list).

It's the problem ^^