Facebook Login API适用于localhost,但不适用于托管服务器

时间:2016-05-23 20:24:51

标签: php facebook-graph-api facebook-php-sdk

我试图用facebook制作登录系统。它在localhost上运行正常,但是当我把它放在网上它没有用。我已在设置中更改了网址的链接,但它无法正常工作。

当我点击登录时,它会进入Facebook,当我允许它进入下一页但由于此而被重定向。

if(!$fbuser){
    $fbuser = null;
        header('Location: ../index.php');
}

这是我的index.php

<?php
ob_start();
include_once("../config.php");
include("admin001.php");
//destroy facebook session if user clicks reset
if(!$fbuser){
    $fbuser = null;
    $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
        header('Location: ../index.php');
}
else{
    $user_profile = $facebook->api('/me?fields=id,name,first_name,last_name,email,gender,locale,picture,link');


    if(!empty($user_profile))
    {
        $image_url = $user_profile['picture']['data']['url'];
        $f_name = $user_profile['first_name'];
        $l_name = $user_profile['last_name'];
        $email = $user_profile['email'];
        $gender = $user_profile['gender'];
        $name = $user_profile['name'];
        $fblink = $user_profile['link'];
        $fbid = $user_profile['id'];
        session_start();
        $_SESSION['fbid']=$fbid;
    }
    else
    {
        header('Location: ../index.php');
    }
}

?>

这是我的config.php

<?php
include_once("inc/facebook.php"); //include facebook SDK
######### Facebook API Configuration ##########
$appId = '***'; //Facebook App ID
$appSecret = '***'; // Facebook App Secret
$homeurl = 'http://isaurav.net/test/index.php';  //return to home
$fbPermissions = 'email';  //Required facebook permissions

//Call Facebook API
$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $appSecret

));
$fbuser = $facebook->getUser();
?>

0 个答案:

没有答案