• Basic Facebook Guide
" How to Install Facebook Farmville Games , Geting Facebook Marketplace App, How to Make Facebook Fan Page, Deleting All Facebook Searches History on FB , How to Login Instagram with Your Facebook , Facebook Marketplace Buy and Sell within Local Community Near Me , How to Deactivate FB Account Temporarily on Facebook, How to View Blocked Facebook List to Unblock blocked Friends , How to Use the “Nearby Me Friends” FB Feature on Facebook , Facebook Customer Care Center & Email Help Supports Contact Addresses "

Facebook Login Facebook Logout

 add fb account, Facebook Login Facebook Logout     No comments   

                                        Facebook Login Facebook Logout                                                                     
 Facebook Login Facebook Logout

This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join Stack Overflow to learn, share knowledge, and build your career.
How to log out user from facebook application, but maintain login from facebook
Ask Question
up vote 9 down vote favorite

I have tried the PHP SDK (v.3.1.1), and the current Javascript SDK as suggested here : https://developers.facebook.com/docs/guides/web/

now when trying to log out I have tried both FB.logout() ( for js ) and $facebook->getLogoutUrl() ;
as the documentation for both clearly state, these methods log the user out of the application as well as their facebook session.
But I only need to log the user out of the facebook application ( the test site ).

I have tried logging the user out of my test site, ignoring the facebook aspect. But in this case, when the user clicks the login button again, the login flow ( facebook authentication and redirect ) does not happen.

I also tried : ( as suggested by previous unresolved questions)$facebook->destroySession(); unset($_SESSION['fb_' . sfConfig::get('app_fb_config_id') . '_code']); unset($_SESSION['fb_' . sfConfig::get('app_fb_config_id') . '_access_token']); unset($_SESSION['fb_' . sfConfig::get('app_fb_config_id') . '_user_id']);

however, when redirecting to the login page, $facebook->getUser() still retrieves the user.
note : as per documentation example, I am using php sdk to login the user to my test site, and the js sdk, to render and facilitate the facebook login button.

additional :
the authentication i use is basically what documentation suggests :<?php define('YOUR_APP_ID', 'YOUR APP ID'); //uses the PHP SDK. Download from https://github.com/facebook/php-sdk require 'facebook.php'; $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => 'YOUR APP SECRET', )); $userId = $facebook->getUser(); ?> <html> <body> <?php if ($userId) { $userInfo = $facebook->api('/' + $userId); ?> Welcome <?= $userInfo['name'] ?> <?php } else { ?> <div id="fb-root"></div> <fb:login-button></fb:login-button> <?php } ?> <script> window.fbAsyncInit = function() { FB.init({ appId : '<?= YOUR_APP_ID ?>', status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> </body> </html>
facebook facebook-javascript-sdk facebook-php-sdk logout

edited Mar 20 '12 at 10:09
asked Mar 20 '12 at 8:51
up vote 5 down vote accepted
Taking your code, and modifying just a bit:<?php define('YOUR_APP_ID', 'YOUR APP ID'); //uses the PHP SDK. Download from https://github.com/facebook/php-sdk require 'facebook.php'; $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => 'YOUR APP SECRET', )); session_start(); $userId = $facebook->getUser(); if ($userId && !isset($_SESSION['fbdata'])) { $_SESSION['fbdata'] = array("userid" => $userId); } ?> <html> <body> <?php if ($userId) { $userInfo = $facebook->api('/' + $userId); ?> Welcome <?= $userInfo['name'] ?> <?php } else { ?> <div id="fb-root"></div> <fb:login-button></fb:login-button> <?php } ?> <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({ appId : '<?= YOUR_APP_ID ?>', status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> </body> </html>
Related Posts:
  • Facebook Login Facebook Logout
  • I Want To Login To My Facebook
  • Fb Log In And Log Out
  • How Do I Retrieve Deleted Facebook Messages
  • I Cant Add My Friend On Facebook
  • How To Sign In Facebook Page
  • How To Edit Name On Facebook Page
  • What Is A Poke Mean On Facebook
  • Can You Retrieve Deleted Messages In Facebook
I just added the saving of the user data into the session. Now, if you use this method, when the user get's into your page you should check if he already has a session, if so all is good no need to authenticate him.

When you want to log the user out of your app, but not out of facebook, just destroy that session:session_start(); session_destroy();

That should remove all saved data you have for the user, next time he visits your page you can start fresh with him.
I'm not a php programmer, and all of the php I used here is from my (very) limited knowledge and what I've found around.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook has greatly reduced the distribution of our stories in our readers' newsfeeds and is instead promoting mainstream media sources. When you share to your friends, however, you greatly help distribute our content. Please take a moment and consider sharing this article with your friends and family. Thank you.

How to Install Facebook Marketplace Near Me App

How to Create a Facebook Business Page

How to Completely Delete Facebook Search History

How to Sign in or Login Instagram with Your Facebook

Marketplace Facebook Buy and Sell within Local Community – Marketplace Facebook Buy Sell App

How to Deactivate FB Account Temporarily on Facebook

How to Find Blocked Facebook List to Unblock blocked Friends

How to Use the “Near Me Friends” Facebook Feature

FB Customer Care Center & Email Help Supports Contact Addresses

How to Install & Play the Facebook Farmville Games
How to Install Facebook Marketplace Near Me App

How to Create a Facebook Business Page

How to Completely Delete Facebook Search History

How to Sign in or Login Instagram with Your Facebook

Marketplace Facebook Buy and Sell within Local Community – Marketplace Facebook Buy Sell App

How to Deactivate FB Account Temporarily on Facebook

How to Find Blocked Facebook List to Unblock blocked Friends

How to Use the “Near Me Friends” Facebook Feature

FB Customer Care Center & Email Help Supports Contact Addresses

How to Install & Play the Facebook Farmville Games

Blog Archive

  • ►  2019 (5)
    • ►  July (5)
  • ▼  2018 (2310)
    • ►  December (2)
    • ►  November (181)
    • ►  October (197)
    • ▼  September (1165)
      • Yahoo mail account sign up
      • Instagram video Icon
      • Add facebook widget to website
      • How to download facebook App
      • Terminate Facebook
      • Restart Facebook
      • How to search for Someone
      • Mobile number Lookup
      • Can you sign up for instagram online
      • Myphone Fb
      • Instagram login sign In
      • My facebook is blocked how do i unblock it
      • How to get more followers on instagram Instantly
      • Page Followers
      • Cannot get Facebook
      • Candy crush saga Android
      • How do i share from facebook to Instagram
      • How to change facebook username Again
      • Whatsapp turn off Facebook
      • Cannot get Facebook
      • Candy crush saga Android
      • How do i share from Facebook
      • how to change facebook username again
      • Whatsapp turn off Facebook
      • Can you hide friends from other friends on Facebook
      • Get off Facebook
      • Gearbox Facebook
      • How to download in facebook Videos
      • Find deleted facebook posts
      • Make your own poll free
      • How to delete list in Facebook
      • Meaning of poke in hindi on Facebook
      • Free online video downloader from any Site
      • Facebook update Verion Download
      • Who viewed my Facebook
      • Facebook logout link Mobile
      • How to delete your old instagram account without P...
      • Our facebook Page
      • Pages for You
      • Facebook new id open Now
      • Can you make a poll on Facebook Page
      • Pet friendly Hotels
      • Goggles
      • Where do you find archived messages on Facebook
      • Facebook blank Page
      • How i change my name in Facebook
      • Unblockedgamescorner
      • How do i delete a group i created on Facebook
      • Forgot Instagram password and Dont have Facebook
      • British army Facebook
      • How to change page url in Facebook
      • Vacation countdown Widget
      • my facebook is blocked how do i unblock it ...
      • Email id login
      • Sign in facebook sign in
      • Mobile facebook Messenger
      • Suspend facebook Page
      • Facebook at work sign up
      • can plus
      • face messenger app
      • How to read archived Facebook Messages
      • www f facebook com login
      • Memories of Facebook
      • Erase Facebook account Forever
      • Download a Messenger App
      • Retrieve lost facebook Password
      • Facebook login friends Search
      • quiz de facebook
      • Poke Poke
      • Fb logout Button
      • How to change name on Facebook before 60 Days
      • How to permanently delete Facebook messages from f...
      • can Instagram
      • How we delete Facebook Account
      • What is followers in Facebook
      • How to convert facebook video to Mp3
      • How to get ur Instagram Password
      • Download Instagram for Tablet
      • How do i know if someone has Facebook Messenger
      • Where can i find location services on Iphone
      • No name Facebook
      • How to unblock ads on Facebook
      • Download foto instagram online
      • How to find a Facebook Stalker
      • Aquarius horoscope Today
      • Facebook login through mobile Number
      • Instagram deleted my Likes
      • Fb sign in and log In Password
      • Delete location on Facebook
      • Log in Facebook Facebook
      • How to unblock ppl on Fb
      • Facebook messenger recovery Tool
      • Facebook operator Number
      • How to know block Facebook
      • Facebook operator Number
      • How to know block Facebook
      • Fejsbuk Log in
      • How to hide Facebook friends list on Mobile
      • How to logout of Instagram on Laptop
      • Can i see who views my Instagram Pictures
    • ►  August (665)
    • ►  July (100)

Copyright © Basic Facebook Guide