Take the 2-minute tour ×

I'm having serious issues concerning Facebook Connect plugin. I'm trying to use this feature in order to let my users login on a website.

So I used basicaly the example given with php SDK mixing JS SDK.

I successfully managed to allow my users to login, but I can't make them logout. I'm becoming mad, I don't understand... It just doesn't work...

Later on I'll use the facebook session in a session php variable so I need to logout destroying both session and cookie. Could you just help me, I almost cry a minutes ago :p

Here is my code :

//uses the PHP SDK.  Download from https://github.com/facebook/php-sdk
require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'ddddd',
  'secret' => 'ddddddddddddddd',

$userId = $facebook->getUser();

 <?php if ($userId) { 
      $userInfo = $facebook->api('/' + $userId); 
      $params = array('next' => 'http://www.nofrenchtouch.com/include/logout.php');
      $logout = $facebook->getlogoutURL($params);?>

      <span class="facebook-in">Bienvenue <?= $userInfo['name']?> - <a href="#" onClick="logoutUser(); return false;" class="facebook-bt"> Se déconnecter</a>
    <?php } else { ?>
    <a href="#" class="facebook-bt" onClick="loginUser(); return false;">Se connecter avec Facebook</a>
    <?php } ?>

          window.fbAsyncInit = function() {
          cookie: true,
          xfbml: true,
          oauth: true
        FB.Event.subscribe('auth.login', function(response) {
        FB.Event.subscribe('auth.logout', function(response) {
         js.src = "//connect.facebook.net/fr_FR/all.js";

       function loginUser() {    
        function(response) {
            getStatus(); //This is a call to a different function...
    {scope:'email,publish_stream, user_birthday, friends_birthday'}

     function logoutUser() {    
        function(response) {

Thanks a lot for reading.


share|improve this question
Where are you destroying the php session at? –  DMCS Feb 14 '12 at 21:13
add comment

2 Answers

When you are logging out of facebook remove your session and cookies of user.

function logoutUser() {    
        function(response) {
//Pass control to function in php where you can destroy your session and cookies.
// windows.location=PHP function
share|improve this answer
add comment

FB.logout(); will log the user out of Facebook. Logging out of Facebook does, essentially, end the session with your server, but I think that that is not what you are trying to achieve. Nonetheless, I have found that the following code works for logging out of Facebook:

<a href="javascript:FB.logout();void(0)">Log Out</a>

When a user grants your application privileges to his or her account, the JS SDK will automatically pass session information about the user to the server every time that a page is loaded. In order to let your user log out, you have to create your own authentication system that can be logged in and out of at will. It will use its own session hashes and whatnot that are separate from the ones that the JS SDK creates. Only use the Facebook PHP SDK to get information about your user and store it in your database. This will allow the user to log out of your website (even though the Facebook JS SDK actually still is connected). I can provide more information on user account systems if you need.

share|improve this answer
Thanks a lot for your help. :-) –  Hugo Trial Mar 17 '12 at 11:06
You're welcome. –  wecsam Mar 17 '12 at 19:02
add comment

Your Answer


