Hi Friends,

I need to write a custom fb connect logout link , so i have write a hook_menu function . at the time of logout its redirecting to facebook , its not clearing facebook session .

when i check the url access token is showing as 0.


function custom_alter_menu() {
    
  $items['custom/login'] = array(
    'page callback' => 'custom_alter_facebook_login',
    'title' => 'Example Page',
    'access arguments' => array('access content'), 
    'type' => MENU_CALLBACK,
  );
  
  $items['custom/logout'] = array(
    'page callback' => 'custom_alter_facebook_logout',
    'title' => 'Example Page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );  
    return $items;  
}


function custom_alter_facebook_logout() {
    
     $client = facebook_client();
     //print_r($client);
     session_destroy();
     global $base_url;
     $url = $client->getLogoutUrl(array('next' => $base_url));
     echo '<script>location.href="'.$url.'";</script>';
     //drupal_goto($url);
    // print $url;
    // die();
}

Any please go through the above function . thx

Comments

nyleve101’s picture

Hi,

I'm also experiencing the issue that logging out causes the user to be redirect to the facebook homepage. This bug only happens in auto login/logout mode.

Did you find a solution?

Thanks,

Ev

aruntvla’s picture

try the latest code

function custom_alter_facebook_logout() {
     session_start();
     $client = facebook_client();
     $fbuid = $client->getUser();
    /* if(isset($_SESSION)) {
     session_destroy();
     } */
     global $base_url;
     $access_token='';
     @$access_token =  $client->getAccessToken();
     $url = $client->getLogoutUrl(array('next' => $base_url,'access_token' => $access_token));
     $client->destroySession();
     if(isset($_SESSION)) {
     session_destroy();
     }
     if(isset($_COOKIE)) {
     unset($_COOKIE); }
   //  if(isset($_SESSION)) { unset($_SESSION[$session_var_name]); }
     drupal_goto($url);
}