Athanatos
Athanatos

Reputation: 1089

facebook how to delete cookie on logout

I am using the JS and PHP SDK and I can login a user successfully using facebook. However logout doesnt seem to work (I can log a user out of my site but not out from facebook ).

Here is my logout code :

require_once('../libs/facebook/src/facebook.php');
$facebook = new Facebook( array (
    'appId'  => 'xxxx',
    'secret' => 'xxxx',
    'cookie' => true
    )
    );

    $fb_key = 'fbsr_'.$facebookConfig['app_id'];

 // set_cookie($fb_key, '', '', '', '/', '');
  //$facebook->setSession(NULL);

$facebook->destroySession();
$facebook->getLogoutUrl();

$_SESSION = array();
session_unset();
session_destroy();
$files = array();
foreach ($_SESSION as $key => $value) {
    $files[] = $key;
    unset($_SESSION[$key]);

}

I have tried to use the following below to delete the cookie but I got an error message that setcookie is not a function

$fb_key = 'fbsr_'.$facebookConfig['app_id'];
setcookie($fb_key, '', time()-3600);
$facebook->destroySession();

Any suggestions will be appreciated.

Upvotes: 2

Views: 2831

Answers (2)

Sander
Sander

Reputation: 233

For some reason I can't post a comment on your question, so here's an 'answer'.

Have you looked at this SO post?
Delete Facebook Session After Login with PHP SDK

More people are struggling on this, from what I've read. And nobody seems to know if there's a native function within the SDK. So unsetting it manually might be your best bet.

Upvotes: 1

ShawnDaGeek
ShawnDaGeek

Reputation: 4150

You need to append a user access token to the logout url.

Example from my app.

 if($_GET['destroy']){
   $facebook->destroySession(); 
 }
$params = array( 'next' => 'https://apps.facebook.com/anotherfeed/?ref=logout&destroy=true', 'access_token' => $access_token);
$logout=$facebook->getLogoutUrl($params); // $params is optional.

Upvotes: 0

Related Questions