Typo3后端用户以编程方式登录

我有typo3 9.5。

如何以typo3方式登录后端用户?

我尝试过

$GLOBALS['BE_USER'] = GeneralUtility::makeInstance('TYPO3\CMS\Core\Authentication\BackendUserauthentication');

$GLOBALS['BE_USER']->user['uid']=2;

$GLOBALS['BE_USER']->start();

但这不起作用。

yhcgyym 回答:Typo3后端用户以编程方式登录

我找到了解决方法:

$GLOBALS['BE_USER'] = GeneralUtility::makeInstance('TYPO3\CMS\Core\Authentication\BackendUserAuthentication');
$GLOBALS['BE_USER']->start();
$GLOBALS['BE_USER']->setBeUserByUid(2);
$GLOBALS['BE_USER']->createUserSession($GLOBALS['BE_USER']->user);
$url = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
本文链接:https://www.f2er.com/3122751.html

大家都在问