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

Having No Session

digitalpoint

Well-known member
#1
I'm trying to figure out the best way that I could serve a page via the XenForo framework, but not initialize a XenForo session for the user...

There are various content we serve through our servers without the user actually coming to our site. It seems silly to waste the resources to create a session when there is no use for it since the user isn't actually ON our site. Plus having an count of 50,000 guests online would look silly on top of it. lol

Some examples of what I mean...

Image that people use on their sites... underneath it all, it's not a static image... it's hitting the database because it's logging visitors to their site (sort of our Google Analytics uses a 1x1 image to track users).

http://geo.digitalpoint.com/a.png

http://ads.digitalpoint.com/ads.php is used for ad delivery to sites using Digital Point Ads...

Like I want to be able to use the framework for caching and database, but no need for a session for users not actually ON the site.

Looking for the equivalent of this in vBulletin:
PHP:
define('SKIP_SESSIONCREATE', 1);
 
R

ragtek

Guest
#2
Hm, why not overwrite
PHP:
protected function _setupSession($action)
    {
        if (XenForo_Application::isRegistered('session'))
        {
            return;
        }

        XenForo_Session::startAdminSession($this->_request);
    }
in your controller?;)
 

digitalpoint

Well-known member
#4
This is what I ended up doing for a page that I wanted to be able to use the basic XF framework (auto-loading classes for example). I needed to use the cache framework, but did not need things like sessions or database access... hopefully it helps someone.

PHP:
$startTime = microtime(true);
$fileDir = dirname(__FILE__);
 
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
 
XenForo_Application::initialize($fileDir . '/library', $fileDir, false);
 
// We need cache
XenForo_Application::getInstance()->addLazyLoader('cache', array(XenForo_Application::getInstance(), 'loadCache'), XenForo_Application::getInstance()->loadConfig()->cache);
$cacheObject = XenForo_Application::get('cache');
 
A

account8226

Guest
#5
I'm trying to figure out the best way that I could serve a page via the XenForo framework, but not initialize a XenForo session for the user...

There are various content we serve through our servers without the user actually coming to our site. It seems silly to waste the resources to create a session when there is no use for it since the user isn't actually ON our site. Plus having an count of 50,000 guests online would look silly on top of it. lol

Some examples of what I mean...

Image that people use on their sites... underneath it all, it's not a static image... it's hitting the database because it's logging visitors to their site (sort of our Google Analytics uses a 1x1 image to track users).

http://geo.digitalpoint.com/a.png

http://ads.digitalpoint.com/ads.php is used for ad delivery to sites using Digital Point Ads...

Like I want to be able to use the framework for caching and database, but no need for a session for users not actually ON the site.

Looking for the equivalent of this in vBulletin:
PHP:
define('SKIP_SESSIONCREATE', 1);
Hey dude,

Have you found a way not to start session on an external page :sick: ?

I don't really get the example above. I'm not using an external page, but it's in one of my add-on controller.

In fact I would like to load the session, but not to show the member in user online.

Regards.
 

digitalpoint

Well-known member
#8
Couldn't you override XenForo_Controller::_setupSession() in your controller?
I believe you are right... I was thinking more in the context of extending a controller and not initializing the session for just some actions. But yes... I believe you could shut down session init for an entire controller if you needed.

Sorry, I had my brain wrapped around the idea of what *I* was trying to do (have a certain controller action that was just serving an image and didn't need a session/authentication).
 

Jake Bunce

XenForo moderator
Staff member
#9
I believe you are right... I was thinking more in the context of extending a controller and not initializing the session for just some actions. But yes... I believe you could shut down session init for an entire controller if you needed.

Sorry, I had my brain wrapped around the idea of what *I* was trying to do (have a certain controller action that was just serving an image and didn't need a session/authentication).
You should be able to do it for a single action too. When _setupSession() runs you have access to the routeMatch in the controller. So in your extended _setupSession() function you can check the action from the routeMatch and conditionally setup the session:

Code:
	protected function _setupSession($action)
	{
		$action = $this->_routeMatch->getAction();

		if ($action == 'youraction')
		{
			// NOTHING
		}
		else
		{
			parent::_setupSession($action);
		}
	}
Untested, but it should work.
 

digitalpoint

Well-known member
#11
Update - okay, I went to see about changing some stuff to use a controller without any queries/sessions.

Ideally you would just want to override XenForo_ControllerPublic_Abstract::_preDispatchType(), but you can't since it's a "final" method.

The _setupSession, _assertViewingPermissions, _assertNotBanned, _isDiscouraged all need to be overridden since they all trigger a query that reads permissions for a guest user.

But even when you do that, XenForo_Dependencies_Public::preRenderView() also triggers the query for guest permissions, and then you start getting into issues where you need to create a whole new listener to override the front_controller to get rid of that query.

So in the end, it *probably* can be done (running something in a public controller that requires no queries), but it starts getting rather complicated, and really not worth it in my opinion.