这可能很简单,但我就是不明白。我正在检查 $userID,如果存在则显示注销 url,否则显示登录 url,但它总是绕过对 userID 的条件检查,即使我正在打印它并且它存在!我一直在用头撞它一段时间,我认为不同的观点可能会有所帮助......
<?php
require_once("fb_login/facebook.php");
$facebook = new Facebook(array(
'appId' => 'MYAPPID',
'secret'=> 'MYSECRETID'
));
$userId = $facebook->getUser();
if ($userID) {
echo("userID is: $userId");
// $params = array( 'next' => 'http://localhost/bcbooks-repo/index_new.php' );
$logoutUrl = $facebook->getLogoutUrl(); // $params is optional.
echo '<a href="' . $logoutUrl . '">logout</a>';
$facebook->destroySession();
}
else{
header("Location: {$loginURL}");
$userId = $facebook->getUser();
$accessToken = $facebook->getAccessToken();
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'http://localhost/bcbooks-repo/index_new.php'
);
$loginUrl = $facebook->getLoginUrl($params);
print_r($_SESSION);
echo("userID is: $userId");
echo '<a href="' . $loginUrl . '">login</a>';
}
?>