简体   繁体   English

facebook php-sdk 没有退出

[英]facebook php-sdk not logging out

I'm having a hard time getting this to work.我很难让这个工作。 I use the following to generate the logout url:我使用以下内容生成注销 url:

$logout = "https://www.facebook.com/logout.php?next=" . urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']) . "&access_token=" . $facebook->getAccessToken();

Which generates the correct (worked with the last version) url:生成正确的(使用最新版本)url:

https://www.facebook.com/logout.php?next=http%3A%2F%2F...&access_token=AA....ZD

However this does not actually log the user out.但是,这实际上并没有将用户注销。 I tried using我尝试使用

$facebook->getLogoutUrl(array('next' => 'myurl')) 

which generates pretty much the same url.它生成几乎相同的网址。 This also did not work.这也没有奏效。 I am lost as to why its not logging the user out.我不知道为什么它没有将用户注销。 I actually tried manually putting the address into the address bar but it redirects me to the Facebook homepage.我实际上尝试手动将地址放入地址栏中,但它会将我重定向到 Facebook 主页。

The facebook php sdk uses php sessions to tokens that keep you logged in. To clear it, you can just destroy the session. facebook php sdk 使用 php 会话来标记让您保持登录状态。要清除它,您只需销毁会话即可。

index.php:索引.php:

<a href="logout.php">Log out</a>

logout.php注销.php

$facebook = new Facebook(array('appId'  => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
$facebook->destroySession();
header('location: index.php');

FB_APP_ID and FB_SECRET are my specific apps info. FB_APP_ID 和 FB_SECRET 是我的特定应用程序信息。 Replace with your own.换成你自己的。

If you request the offline_access permission when using the Facebook PHP SDK (and sometimes even without it), it makes the default logout functionality not work very well.如果您在使用 Facebook PHP SDK 时请求offline_access权限(有时甚至没有它),它会使默认的注销功能无法正常工作。 To fix this, following worked for me:为了解决这个问题,以下对我有用:

//change your logout url to 
$logoutUrl = $facebook->getLogoutUrl(array( 'next' => ($fbconfig['baseurl'].'logout.php') ));

//on logout page
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'domain.com');
session_destroy();
header('Location: /');

It could be because the PHP session and session cookie are still intact. 可能是因为PHP会话和会话cookie仍然完整。 I've written a short article that attempts to demystify FB login/logout at. 我写了一篇简短的文章 ,试图揭露FB登录/注销的神秘色彩。

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

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