This question already has an answer here:
How do I check if a user who is logged in to my website via the facebook php sdk has liked my page so that I can show him some secret content...
</div>
If you have the appropriate permissions you can access the Likes property of the user: you can then check the returned list to see if your URL is in the list. You can use something like this:
$likes = Facebook::api('/me/likes','GET');
Here is another approach using check if $signed_request->page->liked
:
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}
}