özgür
özgür

Reputation: 43

How to log out from Facebook

I used that code to connect to facebook

// Get User ID
$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
ob_clean();
// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

then logOut form facebook

if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
       <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php endif;

if the user clicks the link, then logOut. but I want just running pace code. not link. in the page, ı will work where ı wrote.

I did like that but didn't work

header('Location: '.$logoutUrl );

To sum up: in my page I want to LOGOUT not only in my cookies but also on facebook.

like that:

if(!isset($_COOKIE["kullanici"]))
{
  echo "Giriþ yapmamýþsýnýz  Bu sayfaya giriþ izniniz yoktur...";
  exit();
}
else
{ 
   setcookie("kullanici_mail", "", time()-3600,"/");
  if($user)
  //  here FACBOOK LOGOUT CODE SHOULD BE
  // AND THAN GO 
  ?>
   <script language="JavaScript">
   <!-- Sakla
   parent.location.href="../index.php";
   // -->
   </script>
 <?
}

Upvotes: 0

Views: 143

Answers (2)

user1403947
user1403947

Reputation:

You cannot log a user out of Facebook, but you can log them out of your App:

http://samoldak.com/index.php/fixing-facebooks-php-sdk-logout/

Upvotes: 0

Eelke Sietse
Eelke Sietse

Reputation: 79

I don't quite understand what you want to accomplish here, but you might want to try the destroy session function that comes with the facebook php SDK. Its not documented on the site but it is in there and I think it might be what you need.

$facebook->destroySession;

Upvotes: 1

Related Questions