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