0
votes

I have a website that uses facebook authentication. I have implemented the login & logout functionalities via the following code-

$scope = 'email,publish_actions';
$loginUrl   = $facebook->getLoginUrl(array('scope' => $scope,'redirect_uri'=>$redirect_uri));
$logoutUrl = $facebook->getLogoutUrl(array('next' => $redirect_uri));

Till here its working fine.But the problem starts when i logout via my website.The following happens-

  1. I am logged out of my facebook(verified by refreshing www.facebook.com).
  2. But my website still says,I am logged in.
  3. Also,if I log out via facebook.com,I remain logged in my website though both are in same browser.

I found a post in StackOverflow(I am not find it again,sorry) which said that facebook stores the value of $facebook->getUser() in a session. So what i did was create a logout.php page with simply following code-

<?php
session_start();
session_destroy();
?>

This solves the problem but i have to call the logout.php page manually. So how do i bind a call to logout.php along with call to $logoutUrl and also redirect the user to my original redirect_uri. Or,is there some other way to do the whole process.I am needed to use the PHP SDK for some reason.

1

1 Answers

2
votes

In your logout.php try this

if ($facebook->getLogoutUrl() == TRUE) {
     session_start();
     $facebook->destroySession();
     session_destroy();
     header('location:Youruri'); 
    }