您必须首先调用javascript客户端注销,然后将其发送到php注销脚本。因此,请致电.js:
FB.Connect.logoutAndRedirect("/path/to/zend/logout/controller");
您将看到一个模式弹出窗口,显示“您正在注销此站点和Facebook*,您将被重定向到您的注销脚本所在的位置:
try
{
$facebook->expire_session();
}
catch (FacebookRestClientException $e)
{
//you'll want to catch this
//it fails all the time
}
为了安全起见,我通常也在PHP注销脚本中调用此函数:
/**
* 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]);
}