XF 2.0 Getting user information on PHP page

grantus

Active member
I'm trying to get user info on my own PHP page and I looked around and saw a few examples but I can't get it to work.

I have this:

Code:
<?php
$fileDir = $_SERVER["DOCUMENT_ROOT"];

if ( ! file_exists( $fileDir . '/src/XF.php'  ) ) {
   return false;
}

require( $fileDir . '/src/XF.php' );
\XF::start($fileDir);

$app = \XF::setupApp('XF\Pub\App');
$app->start();

$visitor = \XF::visitor();
$user_id = $visitor['user_id'];

echo 'user_id: '.$user_id;

I get a blank page and this is the error:

Code:
ErrorException: Fatal Error: Cannot redeclare class XF - src/XF.php:7

I need to be able to grab their user_id, username, and maybe a few other variables.

What could be causing the error?

Thanks.
 
Update: My fault! I had this code in a page that I was using in a callback, so I guess XF.php was already being pulled.
 
Top Bottom