'getLogoutUrl' Does not work

2019-07-28 23:33发布

问题:

After I click on my logout button, it redirects me to: https://www.facebook.com/home.php. Why is it that when I return to my app domain, I can still see the logout button...?

Here is my code:

<?php
//User login/logout buttons
if($user) {
    echo '<a href="'.$facebook->getLogoutUrl(array('next' => 'myurl.com/facebook/')).'"><img src="src/logout-fb.png" alt="Facebook Logout Button" /></a>';
}else{
    $params = array(
        scope => 'user_photos, publish_stream',
        redirect_uri => 'http://myurl.com/facebook/'
    );
    $loginUrl = $facebook->getLoginUrl($params);
    echo '<a href="'.$loginUrl.'"><img src="src/login-fb.gif" alt="Facebook Logout Button" /></a>';
}
?>

Thanks in advance.

回答1:

I had the same problem:

When clicking on my logout link, Facebook ignored the "next" parameter, did not logout and redirect to facebook.com/home.php.

I added a final slash to my "next" URL and it solved my problem.

There is my code:

$client = facebook_client();
if($client){
  session_destroy();
  $url = $client->getLogoutUrl(array('next' => $base_url.'/')); //added a slash
  ... //Redirect to $url
}


回答2:

Had similar problem. The URL you're redirecting too needs to be within the your Site Domain as defined within the Developer App. I was testing with google.com for an example and it wasn't logging out.



回答3:

as I guess the URL's should be absolute as below hope this solve your problems... ;-)

$logoutParams = array(
'next'  =>  'http://localhost/Facebook/test/test1/after_logout.php'
);


回答4:

I was facing the same problem in one of my Facebook App. I was putting redirect URL correctly, everything seems fine. But then I realize that my domain is missing in Facebook App settings.

For you Facebook App set your domain e-g "example.com"

Last and important that your Redirect URL in the Facebook's Log out URL should be within your domain you have specified in Facebook App settings.



回答5:

I just added my application's canvas URL in "next" parameter and it works.