开发者

Facebook login to site bugs

开发者 https://www.devze.com 2023-04-12 22:13 出处:网络
When users come to my site they have the option to log in through facebook. If they are logged in to facebook, and hit the fb login button, it will show all the appropriate logged in dialog. However,

When users come to my site they have the option to log in through facebook. If they are logged in to facebook, and hit the fb login button, it will show all the appropriate logged in dialog. However, if you log out of facebook (either through my site or through facebook itself) and then try to log in through my site again, it will bring you to facebook to sign in, then bring you back to my site. The url changes from x.net/index.php to x.net/index.php?state=... bunch of letters / numbers, but then doesn't return logged in dialog. Hit the button once again after that, and the page refreshes with a different (but similar) url, and returns all the logged in dialog.

Any ideas on how to fix this?

Here is the code I use to connect to facebook and get the login and logout urls.

//facebook application
$fbconfig['appid' ]     = "myAppId";
$fbconfig['secret']     = "myAppSecret";
$fbconfig['baseurl']    = "http://myNeatSite.net开发者_开发百科/index.php"; 


if (isset($_GET['request_ids'])){
    //user comes from invitation
    //track them if you need
}

$user            =   null; //facebook user uid
try{
    include_once "facebook.php";
}
catch(Exception $o){
    error_log($o);
}
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

//Facebook Authentication part
$user       = $facebook->getUser();


$loginUrl   = $facebook->getLoginUrl(
        array(
            'scope'         => 'email,publish_stream',
            'redirect_uri'  => $fbconfig['baseurl']
        )
);

$logoutUrl  = $facebook->getLogoutUrl();


if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
 $user = null;
  }
}


As far as I see, you only process the case $user is not null (which means the user is already logged in), but ignore the other case.

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
 $user = null;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号