I have built this standalone script for logging in the user programmatically.
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$basePath = "/web/forum";
// Require the XenForo autoloader
require $basePath . '/src/XF.php';
// Initialize XenForo
XF::start($basePath);
// Set the user ID you want to log in
$userIdToLogin = 13; // Replace with the actual user ID
// Fetch the user
$user = XF::em()->find('XF:User', $userIdToLogin);
XF::app()->session()->set('sessionKey', 12345);
XF::session()->changeUser($user);
XF::setVisitor($user);
But I get the following error:
An exception occurred: [LogicException] The session key must be overridden. in src/XF/App.php on line 816
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$basePath = "/web/forum";
// Require the XenForo autoloader
require $basePath . '/src/XF.php';
// Initialize XenForo
XF::start($basePath);
// Set the user ID you want to log in
$userIdToLogin = 13; // Replace with the actual user ID
// Fetch the user
$user = XF::em()->find('XF:User', $userIdToLogin);
XF::app()->session()->set('sessionKey', 12345);
XF::session()->changeUser($user);
XF::setVisitor($user);
But I get the following error:
An exception occurred: [LogicException] The session key must be overridden. in src/XF/App.php on line 816
- XF\App->XF\{closure}() in src/XF/Container.php at line 28
- XF\Container->offsetGet() in src/XF/App.php at line 2506
- XF\App->session() in test_login_programatically.php at line 20