Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook php SDK getLogoutUrl() problem

Tags:

php

facebook

When i want to logout users from my website i use:

$logoutUrl = $facebook->getLogoutUrl(array('next' => 'logout.php'));

And $logoutUrl displays correct link, however it's not redirecting me to the url specified in next. It redirects me to the page that started logout.

As it looks that there is very much articles on internet, but they all use same methods and for many people those don't work. How to properly logout user from facebook and then perform my regular logout script?

EDIT: This worked but still want some non-javascriptSDK based logout.

<a id="logout" href="logout.php" onclick="FB.logout(function(response) { window.location = 'logout.php' }); return false;" title="<?php echo $lang['logout']; ?>"><?php echo $lang['logout']; ?></a>
like image 797
arma Avatar asked Dec 28 '22 02:12

arma


1 Answers

You should use absolute URLs. e.g.

//   (or https://)
$here = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$next = preg_replace('~#.*$~s', '', $here);
$next = preg_replace('~\?.*$~s', '', $next);
$next = preg_replace('~/[^/]*$~s', '/logout.php', $next);
$logoutUrl = $facebook->getLogoutUrl(array('next' => $next));

Or simply:

$logoutUrl = $facebook->getLogoutUrl(array('next' => 'http://...../logout.php'));
like image 166
Thai Avatar answered Jan 08 '23 11:01

Thai