Pages

Monday, July 9, 2012

Facebook PHP SDK logout : resolved

Facebook sdk is creating one cookie in browser.
Which has to be cleared on logout.
Here is my Codeigniter code to do that.

Logout URL
$this->facebook->getLogoutUrl(array('next' => site_url('user/logout'));


Logout Function

 public function logout() {
    setcookie('PHPSESSID', '', time()-3600, "/");
    $this->session->sess_destroy();
    redirect('/user', 'refresh');
  }

4 comments:

Anonymous said...

Hi there,

Thanks for the code, it works great, thumbs up !!

Cheers!

Anonymous said...

Hi,

I am using php-sdk and all things working except "logout". I have tried your code in my core php code but working.and i am not using code igniter or any other framework.

any suggestion?

Unknown said...

you should check the cookie name.
By default the name is PHPSESSID.
If it is different for you, change in the code.

Anuj Dhingra (India) said...

Added the session_destroy() in getLogoutUrl function.