douzun4443 2013-08-24 08:41
浏览 45

Facebook将URL重定向到index.php

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");
    }
}
?>

For the 1st time I am working on the Facebook app. I have made app on the Facebook developer. It's working properly but it is not redirecting me in the index.php. I want to redirect it in this page only so all the values are stored in the session and I am checking it if the cookies is made then this value is going to registration.php and if not then its going to sbs_login.php. Please can anybody tell where to give the redirect url?

  • 写回答

2条回答 默认 最新

  • dongtang7347 2013-08-24 10:08
    关注
      $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'
    
        ));
    

    I find the solution of my problem . so this is the solution

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器