XF 2.2 Create user session - External PHP File

fahad ashraf

Well-known member
i am trying to create user session from external php file but it is not working i am using below code

PHP:
define('XF_ROOT',$xfPathRoot); 
require(XF_ROOT . '/src/XF.php');

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

            // assume i have user object
                                $app->session()->changeUser($user);
                                \XF::setVisitor($user);
                                
                                $ip = $app->request()->getIp();

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

                                $app->repository('XF:Ip')->logIp(
                                        $user->user_id, $ip, 'user', $user->user_id, 'login'
                                );
                                
                                $visitor=\XF::visitor();
                                $rememberRepo = $app->repository('XF:UserRemember');
        $key = $rememberRepo->createRememberRecord($visitor->user_id);
        $value = $rememberRepo->getCookieValue($visitor->user_id, $key);


can anyone guide what i am doing wrong ??
 
Back
Top Bottom