当用户访问我的网站时,他们可以选择通过Facebook登录。如果他们登录到Facebook,并点击fb登录按钮,它将显示所有相应的登录对话框。但是,如果您退出Facebook(通过我的网站或通过Facebook本身),然后尝试再次通过我的网站登录,它将带您到Facebook登录,然后带您回到我的网站。网址从x.net/index.php更改为x.net/index.php?state = ...一堆字母/数字,但随后不会返回登录对话框。之后再次按下按钮,页面将刷新另一个(但相似的)url,并返回所有已登录的对话框。
有关如何解决此问题的任何想法?
这是我用来连接到Facebook并获取登录和注销网址的代码。
//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;
}
}
答案 0 :(得分:0)
据我所知,您只处理案例$user
不为空(这意味着用户已经登录),但忽略其他情况。
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
}