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 lo
You can logout the facebook user and redirect the user to your website page with PHP code like this :
header("Location: " . $facebook->getLogoutUrl(array('next'=>"http://yourwebsite.com/redirectAfterFacebookLogout.php")));
(NEW FACEBOOK SDK) For me the getconfig() wouldn't work.So I had to find the new functions from the base_facebook.php file and add this bit of code in it. Then call it in your calling file. Before you do , call $facebook->destroySession();
public function _killFacebookCookies()
{
// get your api key
$apiKey = $this->getAppId();
// get name of the cookie
$cookie = $this->getSignedRequestCookieName();
$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]);
}
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");
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
}
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]);
}