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:
When you want to log the user out of your app, but not out of facebook, just destroy that session:session_start(); session_destroy();
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
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.
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.
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.