1
我申請permision確認後重定向「登錄與Facebook」在我的網站。登錄與Facebook不斷從Facebook
當我點擊登錄與Facebook ....它重定向至Facebook請求許可。我點擊確定。之後,它會同時重定向到Facebook和我的網站。
我下面提供我的代碼。任何人都可以幫助我找出重定向錯誤的位置嗎?
這裏是我的代碼:
的index.php
<?php
session_start();
if ($_SESSION['FBID']): ?> <!-- After user login -->
<h1>Hello <?php echo $_SESSION['USERNAME']; ?></h1>
<li><?php echo $_SESSION['FULLNAME']; ?></li>
<div><a href="logout.php">Logout</a></div>
<?php else: ?> <!-- Before login -->
Not Connected
<div><a href="fbconfig.php">Login with Facebook</a></div>
<?php endif ?>
fbconfig.php
<?php
require 'src/facebook.php'; // Include facebook SDK file
//require 'functions.php'; // Include functions
$facebook = new Facebook(array(
'appId' => 'APP_ID', // Facebook App ID
'secret' => 'SECRET', // Facebook App Secret
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$fbid = $user_profile['id']; // To Get Facebook ID
$fbuname = $user_profile['username']; // To Get Facebook Username
$fbfullname = $user_profile['name']; // To Get Facebook full name
$femail = $user_profile['email']; // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['USERNAME'] = $fbuname;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
// checkuser($fbid,$fbuname,$fbfullname,$femail); // To update local DB
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
header("Location: index.php");
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email', // Permissions to request from the user
));
header("Location: ".$loginUrl);
}
?>
好吧,現在它來到index.php,但沒有顯示index.php額外的東西。手段仍然顯示登錄與Facebook鏈接。沒有註銷。 – 2014-10-10 07:11:21
隨着此URL:http://localhost/facebook/index.php代碼= AQAwXra3ApI1A1O0GvMm1l4tFbswTYvhGxSaJydc3M_O4YMdiksaGemsgaysvDuSBTbX3GbRUJO87nTO7228JFSPALfTsTjSvFsQxzDSh8tOKX02pE-Gey中-qqI7TjCKCW9GQkB1gr6PDpz3d3dmXF5fendqxbj8BnnLI7h4FR4WMPNEFTtTYGZQObJlMO9LX0pFxtXNg5-sFLngbs9xRBbqs_s0-7Mj8rSZUCER9Uz_IcCOVoqza-9d4DMMyIyFqD8buo5dSx30G3TmaKn_JAk1Ra2R-CsOK6x-O8kWatVqC9vbsJJQjgubAADmPwd2AyQOP2cAdyN4zpzyQADSYgLqf&狀態= 42e388406e0703b46b4a22d02d9e46a7#_ = _ – 2014-10-10 07:11:53
更改index.php來 getUser(); 如果($用戶): $ user_profile = $ facebook-> API( '/我'); ?><! - 用戶登錄後 - > Logout <! - 登錄之前 - > 未連接 Login with Facebook –
2014-10-10 07:21:41
Hello <?php echo $ user_profile ['name']; ?>