You can check if the user has a valid access token, in other words, was logged on to your site at some point. FB gives you the session data on the front end so get it like this:
FB.getLoginStatus(function(response){
//send the response to the back end in a json string
});
Then validate it on the back end using a modified version of the legacy signature validation. It seams to work. Please let me know if I'm missing something.
It only tells you that the user id, access token match for your site. No curl calls needed.
It doesn't tell you if the session is actually currently valid though so don't rely on it for your banking system or anything.
function validateFB_sessionObj($sessionObj){//pass me the session data object
$sessionObj = $sessionObj->session;
global $fb;//pull in the secret fb keys
if (!is_object($sessionObj) || !isset($sessionObj->uid) || !isset($sessionObj->access_token) || !isset($sessionObj->sig)){
// warning("facebook session object is lacking something", $sessionObj);
return false;
}
$expectedSig = generateSig($sessionObj, $secret);
if ($sessionObj->sig = $expectedSig){
// status("fb signature looks good");
return true;
} else {
// warning("facebook signature looks wrong", $sessionObj);
return false;
}
}
function generateSig($params, $secret){
$string = $params->access_token . $params->uid . $secret;
return md5($string);
}