I am using the PHP Facebook SDK to leverage the Facebook registration/login plugin. I am referring to: http://www.masteringapi.com/tutorials/how-to-use-facebook-registration-plugin-as-your-registration-system/15/
Currently, the browser redirects away from the registration page, no matter if I am signed in to Facebook or not.
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
<?php if($_SERVER['PHP_SELF'] == '/register/index.php'){?>
FB.getLoginStatus(function(response) {
if (response.status == "connected" || response.status == "unknown") {
window.location = "http://<?=SITE_HOST?>/";
}
});
<?php }?>
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
The part that is causing this unwanted redirect is this:
<?php if($_SERVER['PHP_SELF'] == '/register/index.php'){?>
FB.getLoginStatus(function(response) {
if (response.status == "connected" || response.status == "unknown") {
window.location = "http://<?=SITE_HOST?>/";
}
});
<?php }?>
This function is supposed to redirect a "connected"1 user, away from the registration page. Unfortunately, even when I access this page from a brand-new browser (Firefox, just installed, which means no cookies or sessions exist) and I am still redirected. Note the PHP code below[2]. Also, the SITE_HOST is a constant for the www. address.
I think the actual condition that is being met is response.status being equal to "unknown". This status check implies an unsuccessful response from Facebook, right?
Without this getLoginStatus check in the code, it will actually load the the registration page, and a Facebook registration form:
Note how it says: "You have registered", which I did a month ago (assuming this qualification is met by allowing the Facebook App permissions, which was done when I initially installed the Facebook SDK). So why would the redirect code work for me (seemingly), then still redirect me when I am using a browser NOT signed in to Facebook?
Also, the jQuery function at the bottom of the script loads all.js. This is all I need, right?
Footnotes:
Someone with "connected" status is logged in to Facebook and has approved your Facebook App permissions.
No matter which page this was on it caused this, and since this code appears in a global include file, I've restricting from printing to only on the registration page, which was the intention for this code to my understanding.