Facebook login, redirection loop

I am including the facebook login into my web page but I have a problem, at first, the code:

//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
}

The problem is that my code doesn't read the session and makes an infinite loop of redirection :(

Answers


As TommyBS said, there is no getSession in the current php SDK.

Also, keep in mind this:

1) In your app's configuration on facebook, the App Domains, Website With Facebook Login and (if you need it) App on Facebook / Page Tab URL fields should point to the site your are redirecting.

2) Prepare your app with the official javascript sdk AND don't forget the channel file.

3) Prepare your app with the proper P3P headers for facebook iframes.


Need Your Help

Is it possible to use parameterized URL templates with angular $http service

angularjs http resources angular-resource

I'm using $resource for my RESTful api's and love the parameterized URL template for example 'api/clients/:clientId'

System.Web.Helpers HashPassword Salt and Iterations?

c# asp.net passwords cryptography

ASP.net has a System.Web.Helpers.Crypto class for hashing and verifying passwords. It appears to generate the salt on the fly and store it as part of the password hash.