我想成功登錄到一個新的URL後重定向我的網頁..重定向至Facebook登錄後的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;
}
?>
然而,它加載的窗口登錄彈出框裏面的頁面,這是爲什麼以及如何加載它以使其位於主頁面中。
您需要使用JavaScript和測試FLogin的反應,然後再決定行動的方向(你的情況了window.location = HTTP://本地主機:8080/main.php) – Khez 2011-04-02 04:32:50
腦海顯示下面的一些代碼? – aherlambang 2011-04-02 04:56:44
你只在這裏給PHP代碼,html/js現在會更加重要......它高度依賴於你的代碼。但理論上你應該有一個處理這個場景。萬一你不這樣做,我們仍然會找到一個解決方案,只需發佈js – Khez 2011-04-02 05:00:44