您可以真正知道用戶是否通過使用登錄到Facebook JS SDK的FB.getLoginStatus()
方法(但它當然需要一個應用程序)。
即使沒有要求用戶允許任何應用程序,Facebook也會通過返回not_authorized
響應上述方法來揭示用戶是否實際登錄到Facebook。
例子:
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>JS SDK Test</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID from the App Dashboard
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
FB.getLoginStatus(function(response) {
if(response.status == 'connected' || response.status == 'not_authorized') {
// user is logged-in to Facebook
}
});
};
// Load the SDK Asynchronously
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
</body>
</html>
如果你談論的是用戶是否登錄到Facebook的獨立的Facebook登錄到您的網站,這是不可能的。否則,@ ShaneCurran的答案應該有所幫助。 (儘管他引用了JS API,但您也可以在PHP中做類似的工作。) –