PHP:Facebook Connect身份验证问题

时间:2009-12-08 15:09:58

标签: security api authentication facebook openid

我想使用Facebook Connect开发外部网站,而不是自己的登录和注册过程。

在第一页(index.php)上,我有以下登录按钮的代码:

<fb:login-button v="2" size="large" autologoutlink="false" onlogin="window.location='/index.php'">Connect with Facebook</fb:login-button>

对于身份验证,我使用this library for PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="de" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
</head>
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/de_DE" type="text/javascript"></script><script type="text/javascript">FB.init("XYZ");</script>
<?php
error_reporting(E_ALL);
include_once '/XYZ/facebook.php';
include_once 'lib.php';
include_once 'config.php';
$facebook = new Facebook($api_key, $secret);
$user = $facebook->require_login();
$loggedin = FALSE;
if (isset($user)) {
    if ($user != '') {
        echo '<p>Hello <fb:name firstnameonly="true" uid="'.$user.'" useyou="false" /></p>';
        echo '<p><a href="#" onclick="javascript:FB.Connect.logoutAndRedirect(\'/\'); return false">Log out</a></p>';
        $loggedin = TRUE;
    }
}
if ($loggedin == FALSE) {
    echo '<p><fb:login-button onlogin="window.location=\'/\'"></fb:login-button></p>';
}
?>
</body>
</html>

不幸的是,它还没有用。这有什么不对?

当我想访问此页面时,我被重定向到我必须登录的 http://www.facebook.com/login.php?api_key=XYZ&v=1.0&next=XYZ。然后,登录到Facebook后,我再次被重定向。这一次,我到了 https://login.facebook.com/login.php?auth_token=XYZ

1 个答案:

答案 0 :(得分:1)

$user = $facebook->get_loggedin_user();

而不是

$user = $facebook->require_login();

require_login()会强制你进入facebook login.php