PHP-SDK Facebook auth不断重定向 [英] PHP-SDK Facebook auth keeps redirecting
问题描述
我正在尝试将Facebook整合到我正在开发的网络应用程序中。我从Facebook获得了一个api密钥和密钥,并将站点URL设置为 http:// www。 mysite.com/something/app/
I am trying to integrate Facebook into a web app that I am working on. I got an api key and secret key from Facebook, and have set the Site Url to http://www.mysite.com/something/app/
以下代码从 http://www.mysite.com/something/app/signup/xxxx/ 来检测用户是否连接:
The following code is used from http://www.mysite.com/something/app/signup/xxxx/ to detect whether the user is connected or not:
$facebook = new Facebook(array(
'appId' => FB_APIKEY,
'secret' => FB_SECRETKEY,
'cookie' => true
));
$session = $facebook->getUser();
if($session) {
# Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
try{
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e){}
if(!empty($user)){
# User info ok? Let's print it (Here we will be adding the login and registering routines)
echo $user;
} 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);
}
但问题是,当用户被重定向到$ login_url时,它保持重定向回来,创建一个无限循环。
But the problem is, when the user is redirected to $login_url, it keeps redirecting back, creating an infinite loop.
我已经看过SO上的其他类似问题,也在Google上尝试过他们的解决方案但是这并没有帮助我。
I have looked at other similar issues on SO, and also on Google and have tried their solutions but it just didn't help me out.
[更新]
好吧,我想我在做某事如果我以不同的Facebook用户身份登录,我没有被重定向到一个循环中。似乎只有当我使用我自己的Facebook帐户,这是应用程序的管理员。但是在重定向之后,它应该返回getUser()权限..但它不是出于某种原因。
Ok I think I am onto something. If I log in as a different Facebook user, I am not being redirected in a loop. It seems to happen only when I use my own Facebook account, which is the admin of the app. But after the redirect it should return getUser() right.. but it doesn't for some reason.
任何想法?谢谢。
推荐答案
从我的服务器根目录开始,我从头开始一个新的.php文件。有一切都工作正常,所以我发现我自己的代码导致网页重定向。
I started from scratch on a new .php file from the root of my server. There everything was working alright, so I found out that my own code was causing the webpage to redirect.
事实上,这是我的.htaccess文件中的mod_rewrite,因为搞乱了。不知何故,它没有拿起由FB设置的GET变量。所以我需要找出一些东西。但至少我现在知道是什么原因造成的。案件关闭!
In fact, it was the mod_rewrite in my .htaccess file that as messing things up. Somehow it is not picking up the GET variables set by FB. So I need to figure out something for it. But at least I now know what caused the problem. Case closed!
这篇关于PHP-SDK Facebook auth不断重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!