0

我将 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
}

问题是我的代码没有读取会话并进行了无限循环的重定向:(

4

1 回答 1

0

正如TommyBS所说,当前的php SDK中没有getSession。

另外,请记住这一点:

1) 在您在 facebook 上的应用程序配置中,应用程序域、具有 Facebook 登录的网站和(如果需要)Facebook 上的应用程序/页面选项卡 URL 字段应指向您正在重定向的站点。

2) 使用官方 javascript sdk准备您的应用程序,并且不要忘记频道文件。

3) 使用适用于 facebook iframe 的 P3P 标头准备您的应用程序。

于 2012-08-15T03:13:16.447 回答