Facebook将url重定向到index.php

Facebook将url重定向到index.php,php,facebook,url,facebook-graph-api,redirect,Php,Facebook,Url,Facebook Graph Api,Redirect,index.php <?php //facebook application $fbconfig['appid'] = "32@@@@@@@@@@"; $fbconfig['secret'] = "ca2dc@@@@@@@@@@@@@"; $fbconfig['baseurl'] = "http://localhost/sbs/fblogin/index.php"; // if (isset($_GET['request_ids'])) { //user comes fro

index.php

<?php

//facebook application
$fbconfig['appid']   = "32@@@@@@@@@@";
$fbconfig['secret']  = "ca2dc@@@@@@@@@@@@@";
$fbconfig['baseurl'] = "http://localhost/sbs/fblogin/index.php";
//
if (isset($_GET['request_ids'])) {
    //user comes from invitation
    //track them if you need
}

//facebook user uid
try {
    include_once "src/facebook.php";
}
catch (Exception $o) {
    error_log($o);
}
// Create our Application instance.
$facebook = new Facebook(array(
    'appId' => $fbconfig['appid'],
    'secret' => $fbconfig['secret'],
    'baseurl' => $fbconfig['baseurl'],
    'cookie' => true
));

//Facebook Authentication part
$user = $facebook->getUser();


// We may or may not have this data based 
// on whether the user is logged in.
// If we have a $user id here, it means we know 
// the user is logged into
// Facebook, but we don’t know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.


$loginUrl = $facebook->getLoginUrl(array(

    'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos ,user_work_history'

));

$logoutUrl = $facebook->getLogoutUrl();


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

    }
    catch (FacebookApiException $e) {
        //you should use error_log($e); instead of printing the info on browser
        // d is a debug function defined at the end of this file
        $user = null;
    }
}


//if user is logged in and session is valid.
if ($user) {
    //get user basic description
    $userInfo = $facebook->api("/$user?fields=picture,name,email,gender,birthday");
    //$pic = $facebook->api("/$user/pictures");
    $profile  = json_encode($userInfo);
    $res      = json_decode($profile, true);

    $_SESSION['name']      = $res['name'];
    $_SESSION['email']     = $res['email'];
    $_SESSION['id']        = $res['id'];
    $_SESSION['gender']    = $res['gender'];
    $_SESSION['birthday']  = $res['birthday'];
    $_SESSION['img']       = $res['picture']['data']['url'];
    $_SESSION['auth_type'] = "facebook";

    if (isset($_COOKIE['registration']) && $_COOKIE['registration'] == true) {
        header("location:../sbs/registration.php");
    } else {
        header("location:../sbs/sbs_login.php");
    }
}
?>

我找到了问题的解决办法。这就是解决方案

$loginUrl = $facebook->getLoginUrl(array(
        'baseurl' => $fbconfig['baseurl'],
        'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos ,user_work_history'

我找到了问题的解决办法。因此,这就是解决方案

除了代码示例之外,这个答案还将受益于对其功能的解释。除了代码示例之外,这个答案还将受益于对其功能的解释。
$loginUrl = $facebook->getLoginUrl(array(
        'baseurl' => $fbconfig['baseurl'],
        'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos ,user_work_history'