gpt4 book ai didi

php - 错误 310 (net::ERR_TOO_MANY_REDIRECTS):重定向过多。为 Facebook 使用 PHP SDK

转载 作者:搜寻专家 更新时间:2023-10-31 21:13:15 31 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
PHP-SDK too many redirects

我正在尝试将 facebook 登录 session 保存到数据库并使用本地主机作为主机(使用 PHP SDK for facebook)。下面是我的代码。

<?php

require_once 'facebook/facebook.php';
require 'config/fbconfig.php';
require 'config/functions.php';

$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));

$user = $facebook->getUser();

if ($user)
{
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}

if (!empty($user_profile )) {
# User info ok? Let's print it (Here we will be adding the login and registering routines)

$username = $user_profile['name'];
$uid = $user_profile['id'];
$email = $user_profile['email'];
$user = new User();
$userdata = $user->checkUser($uid, 'facebook', $username,$email,$twitter_otoken,$twitter_otoken_secret);
if(!empty($userdata)){
session_start();
$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;

$_SESSION['username'] = $userdata['username'];
$_SESSION['email'] = $email;
$_SESSION['oauth_provider'] = $userdata['oauth_provider'];
header("Location: home.php");
}
} 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(array( 'scope' => 'email'));
header("Location: " . $login_url);
}
?>

home.php 如下所示..

<?php

//Always place this code at the top of the Page
session_start();
if (!isset($_SESSION['id'])) {
// Redirection to login page twitter or facebook
header("location: index.php");
}
else
{
echo '<h1>Welcome</h1>';
echo 'id : ' . $_SESSION['id'];
echo '<br/>Name : ' . $_SESSION['username'];
echo '<br/>Email : ' . $_SESSION['email'];
echo '<br/>You are login with : ' . $_SESSION['oauth_provider'];
echo '<br/>Logout from <a href="logout.php?logout">' . $_SESSION['oauth_provider'] . '</a>';
}
?>

但是浏览器(chrome)抛出了以下错误

 Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

我已尝试清除所有 cookie,但无济于事。让我了解如何处理此错误,或者是否需要更改代码。我也曾尝试在论坛中寻找错误,但他们并没有那么解释,因为它可能是这个领域的新手。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com