XF 2.2 Xenforo2 login is not working from external php page

fahad ashraf

Well-known member
Hello,

I am trying to login from external php but it is not working here is my code


PHP:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


$start_ob = false;

$ob_status = ob_get_status();
if (!is_array($ob_status)) {
    $start_ob = true;
}


$fileDir = "/var/www/html/xf151/xf22";
require($fileDir . '/src/XF.php');
XF::start($fileDir);
$app = XF::setupApp('XF\Pub\App');

$app->start();

if (true == $start_ob) {
    ob_start();
}



$user2 = $app->em()->findOne('XF:User', ['email' => "xenbulletins@gmail.com"]);



$app->session()->changeUser($user2);
\XF::setVisitor($user2);

$ip = $app->request->getIp();

$app->repository('XF:SessionActivity')->clearUserActivity(0, $ip);

$app->repository('XF:Ip')->logIp(
        $user2->user_id, $ip, 'user', $user2->user_id, 'login'
);


$rememberRepo = $app->repository('XF:UserRemember');
$key = $rememberRepo->createRememberRecord($user2->user_id);
$value = $rememberRepo->getCookieValue($user2->user_id, $key);

$app->response()->setCookie('user', $value, 365 * 86400);
 
Back
Top Bottom