注销 Facebook(使用 PHP SDK)和 CodeIgniter
在开始实施 Facebook 身份验证之前,我的注销控制器如下所示:
# Kill the session
$this->session->sess_destroy();
# Redirect back to main page.
redirect('', 'location');
我尝试修改它以将用户也从 Facebook 注销,但没有成功。
# Kill the session
$this->session->sess_destroy();
require 'application/sdk/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '625256',
'secret' => '25256256',
'cookie' => true,
));
$session = $facebook->getSession();
if ($session) {
$location = (string) html_entity_decode($facebook->getLogoutUrl(array('next' => 'http://localhost:8888/taketocollege/')));
header("Location: $location");
exit();
}
# Redirect back to main page.
redirect('', 'location');
我做错了什么?我不打算为此使用 Javascript SDK,因为我希望这一切都在控制器中完成。
谢谢!!
编辑:更清楚一点,问题是会话没有被破坏。我的注销控制器将用户发送到主页,但主页将具有会话的 Facebook 用户重定向到登录页面。因此 Facebook 用户最终会进入登录页面。通常登录页面会自动让他们登录,但是到那时,他们的会话就被破坏了。
Before I started implementing Facebook authentication, my logout controller looked like this:
# Kill the session
$this->session->sess_destroy();
# Redirect back to main page.
redirect('', 'location');
I tried modifying it to log the user out of Facebook as well, but no luck.
# Kill the session
$this->session->sess_destroy();
require 'application/sdk/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '625256',
'secret' => '25256256',
'cookie' => true,
));
$session = $facebook->getSession();
if ($session) {
$location = (string) html_entity_decode($facebook->getLogoutUrl(array('next' => 'http://localhost:8888/taketocollege/')));
header("Location: $location");
exit();
}
# Redirect back to main page.
redirect('', 'location');
What am I doing wrong? I'm not looking to use the Javascript SDK for this since I want it all to be done in the controller.
Thanks!!
EDIT: To be a bit more clear, the problem is that the session isn't being destroyed. My logout controller sends users to the home page, but the home page redirects Facebook users with a session to the login page. So the Facebook users end up on the login page. Normally the login page would automatically log them in, but, by then, their session is destroyed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个“注销”按钮,它指向您的注销控制器,并且您正在尝试让您的注销控制器调用某些内容以使用户从 Facebook 注销。
如果您使用 Facebook 登录用户,则不需要注销控制器。您只需在页面中显示注销 URL:
如果您想在用户注销时清除会话,您需要在
next
页面上执行此操作(对于您来说,http://localhost :8888/taketocollege/
):希望有帮助!
What you have here is : a "Logout" button that points to your logout controller and you are trying to make your logout controller call something to make the user logout from Facebook.
If you log in your users with Facebook, you don't need logout controller. You just display the logout URL in your page :
If you want to clear the session when the user logs out, you wan do it on the
next
page (for you,http://localhost:8888/taketocollege/
) :Hope that helps !
我的代码最初将用户重定向到主页。
该代码将用户重定向到登录页面,因为会话已更改,但并未完全删除。
通过更改最后两行,我能够解决这个问题:
希望它可以帮助别人!
My code initially redirected users to the home page.
That code was redirecting users to the login page since the session had been changed, not completely erased.
By changing the last two lines, I was able to fix this problem:
Hope it helps someone!