I have some code that I am using to log in users via my website using PHP. It seems to work, but the problem is that after hitting the code below, the first time they visit the forum it doesnt recognize them as logged in. If they refresh the page once more they are then logged in.
The code I am running is part of the XENForoSDK:
$userModel = XenForo_Model::create('XenForo_Model_User');
// Set cookie if needed
// Log IP
XenForo_Model_Ip::log($user, 'user', $user, 'login');
// delete current session
$user = $this->getUser();