如何在PHP和Zend中使用Facebook Connect注销用户? [英] How to log out users using Facebook Connect in PHP and Zend?
问题描述
我正在使用PHP和Zend Framework来构建一个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()
他们似乎都没有工作。 >
None of them seem to work.
推荐答案
您必须先调用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注销脚本中调用此函数,只是为了安全: / p>
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屋!