I would like to create a PHP script to check if the user 'Like's the page. If the user likes the page he is redirected to another URL if not the User is asked to like the page and the facebook like button appears so the user can like.
How can this be done please? I managed to get hold of this script and got errors. Any help please?
Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Facebook "If-Like" Application | ThreeDots</title>
</head>
<body>
<?php
include_once( "facebook.php" );
$fbAppArray = array(
'appId' => 'YOUR_APPLICATION_ID',
'secert' => 'YOUR_APPLICATION_SECRET',
'cookie' => true
);
$fbAppObj = new Facebook( $fbAppArray );
$signedRequest = $fbAppObj->getSignedRequest();
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( $signedRequest = parsePageSignedRequest() )
{
if( $signedRequest->page->liked )
{
// What to show the user if he liked the application...
}else{
// Please like the application so you will be able to see the contents...
}
}
?>
</body>
</html>