PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] Facebook SDK logout not working

 December 28, 2021     codeigniter, facebook, facebook-php-sdk, php     No comments   

Issue

I'm using the Facebook PHP-SDK to sign in users and it works fine. I'm having a problem logging users out correctly. After clicking the logout button and then clicking the sign in button it does not redirect the user to Facebook's sign in page, instead it logs them into my site as if the logout wasn't successful. Here is my code to sign in a user:

function authenticate_user()
{
    $CI = & get_instance();
    $CI->config->load("facebook",TRUE);
    $config = $CI->config->item('facebook');
    $CI->load->library('facebook', $config);

    $user = $CI->facebook->getUser();

    if ($user)
    {
        try
        {
            $user_profile = $CI->facebook->api('/me');
            return $user_profile;
        }
        catch (FacebookApiException $e)
        {
            error_log($e);
        }
    }

    return FALSE;

}

public function signin()
{
    $user_profile = authenticate_user();
    if (!$user_profile)
    {   
        $loginUrl = $this->facebook->getLoginUrl(array('scope' => 'email'));
        redirect($loginUrl);
    }

    $this->load->model("user_model");

    if ($userRow = $this->user_model->user_exists($user_profile["id"]))
    {
        set_session($user_profile, $userRow->privileges);
        redirect("member_controller/members");
    }
}

This is my logout code:

public function fb_signout()
{
    $params = array( 'next' => 'http://www.' + $host + '/index.php/authentication_controller/signout');
    redirect($this->facebook->getLogoutUrl($params)); // $params is optional.
}

public function signout()
{
    $this->session->sess_destroy();
    redirect("http://www." + $host + "/");
}

UPDATE:

The SDK was using native PHP sessions and calling $this->session->sess_destroy() would not destroy it, I needed to include session_destroy() in my signout function.


Solution

The facebook SDK uses native PHP sessions but codeigniter doesn't. what you want to do is add session_destroy(); in your signout method to kill PHP native session.

Hope that helps!



Answered By - flopperJ
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing