此网页有一个重定向循环,但没有获取用户ID

I am using the following script of code and the page get stuck to infinite loop as it does not getting user id. Please help me.

<?php
include_once("facebook.php");

# Creating the facebook object  
$facebook = new Facebook(array(  
    'appId'  => 'xxxxxxxxxxxxxxxxxxxxxxxxx',  
    'secret' => 'xxxxxxxxxxxxxxxx',  
    'cookie' => true  
));  

$user = $facebook->getUser(); 
if($user) { 
    try{  
        $user = $facebook->api('/me');  
    } catch (Exception $e){}  
    if(!empty($user)){  
        print_r($user); 
    } 
    else { 
        die("There was an error.");  
    }  
} 
else {  
    $login_url = $facebook->getLoginUrl(array('scope'=>$fbPermissions,'redirect_uri'=>'http://www.mysit.com.com/script/check.php'));
    header("Location: ".$login_url);  
}
?>

Because of this function its going in infinite redirect loop

header("Location: ".$login_url);  

Remove the above line from your code and add this line insted;

echo 'Please <a href="' . $login_url . '">login.</a>';

This link will take you to the page where you can login to the app.

getLoginUrl() generates a new token. If your user is already logged in (with $user_id = $facebook->getUser()), you'll end up with 2 tokens.

Don't ask for the $loginUrl if the user is authenticated already.