2011-11-07 1 views
0

나는이 페이스 북의 로그인 코드테스트 방법 페이스 북에 접속하지 않은 상태에서 로그인 했습니까?

$app_id = "xxxxxxxxxxxxxx"; 
    $app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
    $my_url = "http://xxxxxxxxxxxxx"; 


    $code = $_REQUEST["code"]; 

    if(empty($code)) { 
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection 
    $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
     . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state=" 
     . $_SESSION['state']; 

    echo("<script> top.location.href='" . $dialog_url . "'</script>"); 
    print_r($dialog_url); 
die(); 
    } 

    if($_REQUEST['state'] == $_SESSION['state']) { 
    $token_url = "https://graph.facebook.com/oauth/access_token?" 
     . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) 
     . "&client_secret=" . $app_secret . "&code=" . $code; 

    $response = file_get_contents($token_url); 
    $params = null; 
    parse_str($response, $params); 

    $graph_url = "https://graph.facebook.com/me?access_token=" 
     . $params['access_token']; 

    $user = json_decode(file_get_contents($graph_url)); 
    echo("Hello " . $user->name ."<a href=event.php?app_id=".$app_id."&app_secret=".$app_secret."&code=".$code."&access_token=".$response."> Create Event</a>"); 
    } 
    else { 
    echo("The state does not match. You may be a victim of CSRF."); 
    } 

내가 이미 페이스 북의 웹 사이트에 연결하고있는 경우,이 페이지에 로그인 고려 테스트 할 수 있나요? 로그인 링크가 표시되지 않습니까?

답변

-1

질문은 꽤 오래되었지만 비슷한 상황을 발견 한 사람들에게는 답이 도움이 될 수 있습니다. 내 말은, 당신이 말하고자하는 것은 코드가 성공적으로 페이스 북 계정에 로그인했는지 확인하는 것입니다.

facebook의 보안 설정에는 현재 활성 세션을 볼 수있는 기능이 있으며, 계정에 로그인 한 시간과 장소에 대한 정보를 제공합니다. 당신이 할 수있는 것은 결국 현재 세션의 로그 아웃 최종 활동 & 모든 세션의 로그 아웃이며, 다음 코드를 실행

Account Settings > Security > Active Sessions 

: 아래 때문이다. 이제 브라우저 (또는 다른 장치이지만 브라우저 또는 다른 브라우저를 통해 로그인해도 괜찮습니다)를 통해 로그인하여 더 이상 활성 세션이 있는지 확인하십시오.

+0

질문에 대답하지 않습니다. 사용자가 이미 연결되어있는 경우 로그인 링크가 표시되지 않도록 앱에서 사용자의 로그인 상태를 확인하는 방법을 알고 싶어했습니다. – CBroe

관련 문제