$facebook->getLogoutUrl(); link doesn't log user out of facebook

≡放荡痞女 提交于 2019-12-01 04:16:19
Luis Fernando Villegas

A little late but here goes my contribution:

Use the params when you generating the logout url, there redirects to a page in which you destroy the session using the Facebook API function for that.

Here an example:

$logoutUrl = $facebook->getLogoutUrl(array("next" => "http://mydomain.com/page4logout"));

In the page4logout you can instance the facebook object and execute the following:

$facebook->destroySession();

After that you can do a redirection.

delete the facebook cookie and session manually. Here is my solution how I solved the problem some time ago, it think it's a bug of Facebook:

setcookie('fbs_'.$this->getAppId(), '', time()-100, '/', $_SERVER["SERVER_NAME"]);
unset($_SESSION['fb_'.$this->getAppId().'_code']);
unset($_SESSION['fb_'.$this->getAppId().'_access_token']);
unset($_SESSION['fb_'.$this->getAppId().'_user_id']);
unset($_SESSION['fb_'.$this->getAppId().'_state']);

$this->getAppID is your Facebook App ID, should be clear ;o)

One way you can check this is by using the PHP SDK and JavaScript SDK together.

When the user visits your site, call FB.getLoginStatus() and check that the authResponse.userID matches what the PHP SDK returns in $facebook->getUser(); (you can do this via a AJAX call if it helps).

You know that if the user ID doesn't match then something is wrong here. Calling $facebook->getLogoutUrl() should log the user out of both your site and facebook, but if it doesn't, try using session_destroy() in your code to clear the sessions. Then redirect the user back to $facebook->getLoginUrl() and get them to login again. This will correct the mis-match in the user ID and you can repeat the process when they come back to your site.

I've seen this happen on other apps, which leads me to believe that this is a facebook issue. The JavaScript SDK doesn't appear to check if the cookie is still valid (if it already exists).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!