2
votes

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 ?

2
So... you click logout, and when the page comes back, it still echo's their ID, when it shouldn't - correct? What's the link that's being generated? - Dave
@Dave Yes, Links you are saying is logout url ? - Justin John
What is the actual URL that's created for the logout link? - Dave

2 Answers

2
votes

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.

0
votes

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();