PDA

View Full Version : Logout code not working.


5to10pm
04-14-2017, 10:11 PM
I modified my php.ini to set session domain

session.cookie_domain='.maindomain.com'

In VB, I changed cookie domain to .maindomain.com. And implemented single sign on on external page using this code (https://www.vbulletin.com/forum/blogs/david-grove/4327147-how-to-log-into-vbulletin-from-an-external-script-on-your-website). Using latest vBulletin i.e. 5.3.0
I also want to implement auto logout feature. So here is the code that I wrote:

// Path to your vBulletin installation
$vbpath = 'D:/XAMPP/htdocs/forum.maindomain.com/';

// Start login script
define('CSRF_PROTECTION', false);
require_once($vbpath . '/includes/vb5/autoloader.php');
vB5_Autoloader::register($vbpath);
vB5_Frontend_Application::init('config.php');

////logout
$api = Api_InterfaceAbstract::instance();
$userid=false;
$userInfo = $api->callApi('user', 'fetchProfileInfo', array($userid)); //need logouthash, so calling fetchprofileinfo
if(!empty($userInfo)){
//echo $userInfo['logouthash'].'<br>';
$x=$api->callApi('user', 'logout', array($userInfo['logouthash']));
var_dump($x); ///output: array(2) { ["sessionhash"]=> string(32) "7539b3b1778217bd012ef1dce83019b6" ["apiaccesstoken"]=> NULL }
}

But the above code is not working. somebody, please provide working external logout script.

Thank you in advance

--------------- Added 1492219558 at 1492219558 ---------------

I don't know why, but deleting the cookies after calling the logout did the trick

setcookie("bbsessionhash", "", -1, '/', ".maindomain.com");
setcookie("bblastvisit", "", -1, '/', ".maindomain.com");
setcookie("bblastactivity", "", -1, '/', ".maindomain.com");
setcookie("bbpassword", "", -1, '/', ".maindomain.com");
setcookie("bbuserid", "", -1, '/', ".maindomain.com");