简体   繁体   English

Facebook php SDK getLogoutUrl()问题

[英]Facebook php SDK getLogoutUrl() problem

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. 并且$logoutUrl显示正确的链接,但是它没有将我重定向到下一个指定的url。 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? 如何正确地从Facebook注销用户,然后执行我的常规注销脚本?

EDIT: This worked but still want some non-javascriptSDK based logout. 编辑:这工作但仍然想要一些非基于javascriptSDK的注销。

<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>

You should use absolute URLs. 您应该使用绝对URL。 eg 例如

//   (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'));

I know this is old, but the reason getLogoutUrl() isn't redirecting to your "next" url is because it doesn't log the user out or redirect at all. 我知道这是旧的,但是getLogoutUrl()没有重定向到你的“下一个”url的原因是因为它没有记录用户或重定向。 It simply gives you the proper url which you need to use to do the logout and redirect (eg header("Location: $logoutUrl")). 它只是为您提供了正确的URL,您需要使用它来进行注销和重定向(例如header(“Location:$ logoutUrl”))。 After you redirect, the user will be logged out and your "next" url will be called. 重定向后,用户将被注销,您的“下一个”网址将被调用。

Note: do not clear out the Facebook session variables (eg destroySession) before calling getLogoutUrl(). 注意:在调用getLogoutUrl()之前,不要清除Facebook会话变量(例如destroySession)。 If you do, the access token included in the returned url will equal 0 instead of your access token. 如果这样做,返回的URL中包含的访问令牌将等于0而不是您的访问令牌。

The documentation isn't too clear on this, but the function is very appropriately named. 文档对此不太清楚,但功能名称非常恰当。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM