如何使用facebook SDK注销用户? [英] How to log out user using facebook SDK?
问题描述
我正在使用 facebook
使用 facebook php sdk
登录我的网站。
I am using a facebook
log in for my web site using facebook php sdk
.
我注意到的是注销
链接没有做任何事情。注销后,用户仍然可以浏览网站。这是我的代码 facebook.php
:
What I noticed is the logout
link doesn't do anything. After I logout, the user can still navigate the site. Here is my code in facebook.php
:
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '*************',
'secret' => '******************************',
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl();
echo "<a href='$loginUrl'>login</a>";
$logoutUrl = $facebook->getLogoutUrl();
echo $loginUrl;
if($user){
session_start() ;
$_SESSION['user_info'] = $user;
$_SESSION['user_pro']= $facebook->api('/me');
print_r($_SESSION);
}
else{
echo 'not logged in ';
}
echo "<a href='example.com/logout.php'>log out </a>"
?>
这个代码
在登录时工作正常。注销链接应该会破坏会话。这是页面的标题:
This code
works fine on log in. The log out link should destroy the session. Here is the header of the page:
<?php
print_r($_SESSION) ;
header('example.com') ;
?>
我的 logout.php
页面的问题是否没有检测到会话。我不知道这是否是一个 facebook api
问题或我的 php
问题。
The problem with my logout.php
page is it doesn't detect the session at all. I don't know if this is a facebook api
problem or my php
problem.
如何使用facebook SDK登录用户?
How do you log the user out using the facebook SDK?
推荐答案
p>您可以从您的网站和Facebook注销,如下所示:向您的网站提供下一个参数并销毁会话
You can logout from your site as well as from facebook as follow by providing your site url to next parameter and destroying session
$token = $facebook->getAccessToken();
$url = 'https://www.facebook.com/logout.php?next=' . YOUR_SITE_URL .
'&access_token='.$token;
session_destroy();
header('Location: '.$url);
您还必须将其从您的网站登录,您必须防止您的网站自动记住您的用户并立即重新登录。
You also have to log them out of your website AND you have to prevent your website from automatically remembering your user and re-logging them in immediately.
禁用用户自动登录的代码,并尝试重新注销。销毁会话不会阻止您的网站为被记住的用户创建一个全新的有效会话。
Disable the code that auto-logs in your user and try to logout again. Destroying the session will not prevent your site from creating a brand new valid session for the remembered user.
这篇关于如何使用facebook SDK注销用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!