This might be something simple, but I'm just not getting it. I'm doing a check for $userID, and if it exists show a logout url, otherwise show the login url, but it's always bypassing the conditional check for userID, even though I'm printing it out and it exists! I've just been banging my head against it for a while and I think a different perspective might help...
<?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>';
}
?>