1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Grab session info in an external PHP file

Discussion in 'Development Tutorials [Archive]' started by Benjy, Nov 15, 2010.

  1. Benjy

    Benjy Well-Known Member

    Here's the code allowing to include the xenForo framework inside an "external" PHP file (eg. if you don't want to use the template system... but cookies must be accessible), thus accessing visitor (and other) data. Comments are welcome.
    $startTime microtime(true);
    $fileDir dirname(__FILE__) . '/xf'//my xenForo install is located in webroot/xf/ and my script is in webroot/

    require($fileDir '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir '/library');

    XenForo_Application::initialize($fileDir '/library'$fileDir);

    FooBar extends XenForo_Controller
        public function 
    $this->responseError(new XenForo_Phrase('do_not_have_permission'), 403);

    $controller = new FooBar(new Zend_Controller_Request_Http(), new Zend_Controller_Response_Http(), new XenForo_RouteMatch());
    I'm not sure if extending the XenForo_Controller class is the best way to go, or if we should intialize XenForo_Session "by hand". Anyways, once these lines are executed, you can simply instantiate the visitor class with a simple
    $visitor XenForo_Visitor::getInstance();
    boooooo likes this.
  2. Benjy

    Benjy Well-Known Member

    Ah, wrong forum... could a moderator move this to "Development Tutorials and Resources" please?

Share This Page