Facebook登录,重定向bucle
问题描述:
我包括Facebook登录到我的网页,但我有一个问题,首先,代码:Facebook登录,重定向bucle
//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
}
的问题是,我的代码不读取会议和使得重定向:(的无限bucle
答
正如TommyBS说,没有在当前的PHP SDK没有的getSession
而且,记住这一点:
1)在你的应用程序的configur Facebook上的应用程序,应用程序域名,使用Facebook登录的网站和(如果您需要)Facebook/Page Tab页面上的应用程序URL字段应该指向您正在重定向的网站。
2)使用official javascript sdk准备您的应用程序,并且不要忘记频道文件。
3)用适当的P3P headers for facebook iframes准备您的应用程序。
就我所知,getSession不是当前php-sdk https://developers.facebook.com/docs/reference/php/中的一种方法,所以它永远不会被填充或者你没有使用php-sdk但你自己的系统? – TommyBs 2012-08-11 11:27:55