如何在 PHP 和 Zend 中使用 Facebook Connect 注销用户? [英] How to log out users using Facebook Connect in PHP and Zend?
问题描述
我正在尝试使用 PHP 和 Zend 框架构建一个 Connect 应用程序.我还有一个基于 Zend_Auth 的用户认证系统.现在,我可以使用 Facebook 登录,但无法退出.
I am trying to build a Connect app using PHP and the Zend Framework. I also have a Zend_Auth based user authentication system. Now, I am able to log in using Facebook but log out is not working.
我需要清除 Zend_Auth 身份并删除所有 Facebook 登录信息.这样做的最佳方法是什么?
I need to clear the Zend_Auth identity as well as remove all Facebook login info. What would be the best way to do this?
我一起尝试了 facebook_client->expire_session()
和 facebook_client->clear_cookie_state();
以及 facebook_client->logout($next)
在调用 Zend_Auth::getInstance()->clearIdentity()
I tried facebook_client->expire_session()
and facebook_client->clear_cookie_state();
together and also facebook_client->logout($next)
after calling Zend_Auth::getInstance()->clearIdentity()
它们似乎都不起作用.
推荐答案
您必须先调用 javascript 客户端注销,然后将它们发送到您的 php 注销脚本.所以,调用 .js:
You have to call the javascript client logout first, then send them to your php logout script. So, call .js:
FB.Connect.logoutAndRedirect("/path/to/zend/logout/controller");
您会看到一个模态弹出窗口,上面写着您正在退出此站点和 facebook* 您将被重定向到您的退出脚本所在的位置:
You'll see a modal popup that says "you are logging out of this site and facebook* You'll be redirected to wherever your logout script is:
try
{
$facebook->expire_session();
}
catch (FacebookRestClientException $e)
{
//you'll want to catch this
//it fails all the time
}
为了安全起见,我通常也在 PHP 注销脚本中调用这个函数:
I usually also call this function in the PHP logout script, just to be safe:
/**
* Remove the local Facebook cookies that get set manually
*
* @return void
*/
protected function _killFacebookCookies()
{
// get your api key
$apiKey = $this->getConfig()->getApiKey();
// get name of the cookie
$cookie = $this->getConfig()->getCookieName();
$cookies = array('user', 'session_key', 'expires', 'ss');
foreach ($cookies as $name)
{
setcookie($apiKey . '_' . $name, false, time() - 3600);
unset($_COOKIE[$apiKey . '_' . $name]);
}
setcookie($apiKey, false, time() - 3600);
unset($_COOKIE[$apiKey]);
}
这篇关于如何在 PHP 和 Zend 中使用 Facebook Connect 注销用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!