2

成功登录后,我正在尝试将我的页面重定向到新的 url..

<?php
      include_once "fbmain.php";
    $config['baseurl']  =   "http://localhost:8080/index.php";;

    // login or logout url will be needed depending on current user state.
    if ($fbme) {
      $logoutUrl = $facebook->getLogoutUrl(
        array(
            'next'      => $config['baseurl'],
        )
      );
    } else {
      $loginUrl = $facebook->getLoginUrl(
        array(
            'display'   => 'popup',
            'next'      => $config['baseurl'] . '?loginsucc=1',
            'cancel_url'=> $config['baseurl'] . '?cancel=1',
            'req_perms' => 'email,user_birthday',
        )
      );
    }

    // if user click cancel in the popup window
    if (isset($_REQUEST['cancel'])){
        echo "<script>
            window.close();
            </script>";
    }

    if ($fbme && isset($_REQUEST['loginsucc'])){
        //only if valid session found and loginsucc is set

        //after facebook redirects it will send a session parameter as a json value
        //now decode them, make them array and sort based on keys
        $sortArray = get_object_vars(json_decode($_GET['session']));
        ksort($sortArray);

        $strCookie  =   "";
        $flag       =   false;
        foreach($sortArray as $key=>$item){
            if ($flag) $strCookie .= '&';
            $strCookie .= $key . '=' . $item;
            $flag = true;
        }

        //now set the cookie so that next time user don't need to click login again
        setCookie('fbs_' . "{$fbconfig['appid']}", $strCookie);

        echo "<script>
            window.close();
            window.opener.location.reload();
            </script>";
    }

    //if user is logged in and session is valid.
    if ($fbme){
       header("Location: http://localhost:8080/main.php");
       exit;
    }

?>

但是,它会在窗口登录弹出框内加载页面,这是为什么以及如何加载它以使其位于主页中。

4

3 回答 3

0

我已经使用 facebook javascript api 做到了这一点。

FB.init({
appId: '<?= FACEBOOK_APP_ID ?>', 
status: true,
cookie: true, xfbml: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.href='/app/home.php';
}); 
于 2011-04-02T05:24:40.603 回答
0

“下一个”不起作用,但“redirect_uri”做的工作!

$params = array( 'redirect_uri' => 'http://yourdomain/fb_api/login_success.php' );
$loginUrl = $facebook->getLoginUrl($params);
于 2013-07-01T04:08:36.130 回答
0

改变

if ($fbme){
       header("Location: http://localhost:8080/main.php");
       exit;
    }

到脚本的开头

您也可以取出display' => 'popup',并设置重定向uri,以便人们安装应用程序然后返回原始站点,这样他们将在成功安装后重定向。

于 2012-12-16T01:59:23.573 回答