Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:56:05+00:00 2026-06-05T22:56:05+00:00

how do you logout the user from your site in facebook api, while still

  • 0

how do you logout the user from your site in facebook api, while still keeping the user logged into facebook with cakephp? (I found the answer so wanted to share with everyone).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:56:06+00:00Added an answer on June 5, 2026 at 10:56 pm

    I figured this one out just now, after reading CakePHP facebook integration logout issue with CakePHP-Facebook-Plugin.

    Basically, although in the demos with webtechnick’s examples, he puts the “Facebook.Connect” component in the AppController, if you want the selective logout piece, the Best place to put it is in reality within the actual controllers that you want to use it in. That or leave it in AppController and pass noAuth=> true into the Facebook.Connect component.

    Either way, whichever way you choose, you set up one controller (facebook_controller.php?) to handle the facebook logins, and set its component with the noauth set to false (which is default, meaning DO authenticate [read connect.php to understand this]). That way, you have total control over when the users are logged into the site, and you can ACTUALLY log them out (with the regular redirect($this->Auth->logout()) without having the connect component immediately log them back in on redirect. Here is an implementation below:

    Let me give you an idea:

    app_controller.php

    class AppController extends Controller {
        var $components = array('Auth', 'Acl', 'Session');
           //or if you want access to "$this->Connect" universally:
           //   array('Auth', 'Facebook.Connect' => 
           //                      array('noauth'=>'true'), 'Acl', 'Session');
    }
    

    users_controller.php:

    class UsersController extends AppController{
    var $helpers = array('Facebook.Facebook');
            //an example of the users controller, enabling connect, but
            // not authorizing the user (because logout() used by Auth is here)
        var $components = array('Email', 'Session', 'Facebook.Connect' => array('createUser'=>false, 'noauth'=>true));
    
            //login() doesnt need to be shown and can be left alone for your traditional users
    
            function logout(){
                  //if there is no fb user, do the logout normal
                  if ($this->Connect->FB->getUser() == 0){
                        $this->redirect($this->Auth->logout());
            }else{
                    //ditch FB data for safety
                    $this->Connect->FB->destroysession();
                    //hope its all gone with this
            session_destroy();
                    //logout and redirect to the screen that you usually do.
            $this->redirect($this->Auth->logout());
            }
            }
    }
    

    your “facebook_controller.php”:
    class FacebookaController extends AppController {
    …
    // i dont personally like to have his piece create my user so:
    var $components = array(‘Facebook.Connect’ => array(‘createUser’=>false));
    …

    function login(){
    //just need this stub function for later
    $this->autoRender = false;
    }
    
    //you also need this for deauths or they will still be able to get into the site after deauth (against policy or whatever)
        function deauthorize(){
        //get user id from facebook API
        $uid = $this->Connect->FB->getUser();
        $record = $this->User->findByFacebookId($uid);
        $this->User->delete($record['id'], FALSE);  
        }
    }
    

    now your users/login.ctp file:

    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'your app id', // App ID
          channelUrl : '//'+window.location.hostname+'/facebook/channel', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });
    
        // Additional initialization code here
        FB.Event.subscribe('auth.statusChange', function(response){
            if (response.status == "connected"){
                alert('redirecting you to auto facebook login');
                    //here is out default place for login
                window.location.href = "http://"+window.location.hostname + "/facebook/login";
            }
        });
      };
    
      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>
    <?php e($this->Facebook->login(array('registration-url'=>'http://www.yoursite.com/facebook/signup'))); ?>
    

    And that should be pretty much it. I hope this helps someone reading this who still needs the help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to logout the user from our site when they logged out from Facebook?
I need a link in django template which turns into logout if user is
Before my application is going to be closed I have to logout user from
How can I login to AD without logout from current user and get new
I have detailed stats on user access to my system detailing login and logout
Im making a login/logout class that logs users in, sets cookies based on user's
I've been asked to look at a database that records user login and logout
I am trying to implement Facebook Connect functionality into a website that I am
Going over the Facebook API and I'm a bit confused on the right approach.
Im using a jquery script that grabs my posts from facebook and then displays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.