Justin John
Justin John

Reputation: 9616

Logout url in Facebook PHP SDK not working correct

I am trying to connect cake php with Facebook PHP SDK

In App_Controller beforeFilter function

$facebook = new Facebook(array(
      'appId'  => Configure::read("FB_APP_ID"),
      'secret' => Configure::read("FB_APP_SECRET"),
    ));

    // Get User ID
    $user = $facebook->getUser();
pr($user);
$logoutUrl = $facebook->getLogoutUrl();
$loginUrl = $facebook->getLoginUrl();

$this->set(compact('logoutUrl'));

In view.ctp

<a href="<?php echo $logoutUrl; ?>">Logout</a>

Here i already sign in application with facebook, but when i try to logout using logoutUrl, I always get user id of user who was login before I clicked the logout .

$user = $facebook->getUser();
// always get the user id.
pr($user);

Why this happens, whether logout url is not working ?

Upvotes: 2

Views: 1613

Answers (2)

Ben
Ben

Reputation: 2045

Kachar is right about the getLogoutUrl() performing a logout from Facebook not your application. I couldn't find any reference to the $this->Auth->logout(); command though. I found that I needed to unset the session data in order to logout from my app.

session_start();
session_unset(); // The important line, must be called after session_start()
session_destroy();

Upvotes: 0

kachar
kachar

Reputation: 2548

May be the log-out button is logging out the user from Facebook, not from your application.

You have to use $this->Auth->logout(); to logout the user from your application.

Upvotes: 2

Related Questions