1

我正在通过 php 对 XenForo 用户进行身份验证。

我的代码:

public function Auth($username, $password)
{
    $userIDA = $this->getarray("SELECT * FROM xf_user WHERE username='".$username."'");

    if($userIDA) 
    {
        define('SESSION_BYPASS', false); // if true: logged in user info and sessions are not needed
        require_once('library/XenForo/Autoloader.php');

        $AutoLoader = XenForo_Autoloader::getInstance();
        $AutoLoader->setupAutoloader('library');
        XenForo_Application::initialize('library', '');
        XenForo_Application::set('page_start_time', microtime(true));
        XenForo_Application::disablePhpErrorHandler(); //
        XenForo_Session::startPublicSession(); //
        error_reporting(E_ALL & ~E_NOTICE); // Turn off the strict error reporting.

        $db = XenForo_Application::get('db');
        $result = $db->fetchCol('SELECT user_id FROM xf_user WHERE username='.$db->quote($username));
        $user_id = $result[0];
        $result = $db->fetchCol('SELECT data FROM xf_user_authenticate WHERE user_id='.$db->quote($user_id));
        $data = $result[0]; 

        $auth = NULL;

        if(class_exists('XenForo_Authentication_Core12'))
            $auth = new XenForo_Authentication_Core12;
        else if(class_exists('XenForo_Authentication_Core'))
            $auth = new XenForo_Authentication_Core;

        $auth->setData($data); 

        if ($auth->authenticate($user_id, $password))
        {
            switch (intval($user_id))
            {
                default: 
                    return 1; 
                break;
                case 1:
                    return -1; 
                case 3:
                    return -1;
                break;
            }
        }
        return 2;
    }
    else return 3;
}

错误日志:

[2017 年 8 月 12 日 20:08:45 UTC] PHP 致命错误:无法在线重新声明 /home/*******/*******/library/XenForo/Autoloader.php 中的类 XenForo_Autoloader 16

所以,请帮助我,有什么问题

4

1 回答 1

0

尝试使用以下代码,

XenForo_Autoloader::getInstance()->setupAutoloader($forum_directory . '/library');

于 2017-08-13T07:46:02.573 回答