简体   繁体   中英

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>
 <?
}

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;

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM