2
我遇到Facebook登录和PHP问题。PHP使用Facebook登录创建无限重定向循环
下面的文件似乎是造成这个问题。 一切正常,直到我与Facebook成功登录,并重新导向到这个文件时,浏览器最终必然引发无限重定向错误的位置。最后的else语句总是被执行导致循环...
任何想法? 在此先感谢!
<?php
require 'facebook/facebook.php';
require 'config/fbconfig.php';
require 'config/functions.php';
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
if (!empty($user_profile)) {
# User info ok? Let's print it (Here we will be adding the login and registering routines)
$username = $user_profile['name'];
$uid = $user_profile['id'];
$email = $user_profile['email'];
$user = new User();
$userdata = $user->checkUser($uid, 'facebook', $username,$email,$twitter_otoken,$twitter_otoken_secret);
if(!empty($userdata)){
session_start();
$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;
$_SESSION['username'] = $userdata['username'];
$_SESSION['email'] = $email;
$_SESSION['oauth_provider'] = $userdata['oauth_provider'];
header("Location: home.php");
}
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl(array('scope' => 'email'));
header("Location: " . $login_url);
}
?>
尝试注释'header(“Location:home.php”);'和'header(“Location:”)。 $ login_url);',然后看看你是否仍然卡住...... – 2013-03-06 03:43:34
当你在页面顶部放置'session_start();'时会发生什么?每[登录服务器端应用程序(http://developers.facebook.com/docs/howtos/login/server-side-login/)会议是必需的。然后你从请求中获得一个'$ _GET ['code']'状态。 – Jon 2013-03-06 03:52:14