我将 facebook 登录包含在我的网页中,但我有一个问题,首先,代码:
//FACEBOOK LOGIN
if($_GET['method']=='facebook'){
require("_facebook.php");
$session_fb = $facebook->getSession();
if(!empty($session_fb)) {
//Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
$uid = $facebook->getUser();
$user = $facebook->api('/me');
if(!empty($user)){
//We have an active session, let's check if we have already registered the user
$query = mysql_query("SELECT * FROM ".PREFIX."user WHERE oauth_provider = 'facebook' AND oauth_uid = ". $user['id']);
$ds = mysql_fetch_array($query);
//If not, let's add it to the database
if(empty($ds)){
$query = mysql_query("INSERT INTO ".PREFIX."user (oauth_provider, oauth_uid, username, email) VALUES ('facebook', {$user['id']}, '{$user['name']}', '{$user['email']}')");
$query = mysql_query("SELECT * FROM ".PREFIX."user WHERE userID = " . mysql_insert_id());
$ds = mysql_fetch_array($query);
}
// this sets variables in the session
$_SESSION['oauth_uid'] = $ds['oauth_uid'];
$_SESSION['oauth_provider'] = $ds['oauth_provider'];
$_SESSION['ws_auth'] = $ds['userID'].":".$ds['password'];
$_SESSION['ws_lastlogin'] = $ds['lastlogin'];
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
setcookie("ws_auth", $ds['userID'].":".$ds['password'], time()+($sessionduration*60*60));
$login = 1;
}
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();
header("Location: ".$login_url);
}
//end fblogin
}
问题是我的代码没有读取会话并进行了无限循环的重定向:(