I have come across some businesses offering discounts, offers, video downloads, documents etc. to users on Facebook and in return they ask them to simply Like their page. This is quite a good idea as it helps them to attract leads/sales from Facebook and it serves as an additional revenue generation model apart from search engines.
Take for example the following application on Facebook for a UK based retailer
They are offering discounts to Facebook users who Like the above URL. Once you click on
the Like button on the top right the page will display the discount code which customers
can then use to get discount on their purchase.
I was fascinated by this and was curious to know more about how they were doing it as
store owners would definitely benefit from this. I set about creating an application and
after it was done I tried using the FB.Event.subscribe method which was being advocated
by everyone to use to track the click event on the Like button. Though they were correct,
this was working only when the Like button was embedded on the actual page but was not
working in the above case.
I then tried to check whether any thing was being passed to my application from Facebook
and sure enough a signed_request variable was being sent but it was sending a long
alphanumeric string. I sensed that this was encrypted so I Googled and found a method to
decrypt the string.
$signed_request = $_REQUEST["signed_request"]; list($encoded_sig, $payload) = explode('.', $signed_request, 2); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
When I dumped the $data variable it printed out the complete array and displayed it as follows:
Array ( [algorithm] => HMAC-SHA256 [issued_at] => 1353404943 [page] => Array ( [id] =>
[liked] => [admin] => ) [user] => Array ( [country] => pk [locale] => en_US [age] => Array ( [min] => 0 [max] => 12 ) ) )
From above we can check for the value returned in $data[‘page’][‘liked’]. If it’s 1 then
the page is liked by the user other wise the page is not liked.
In this way you can display two different pages to the Facebook user depending on their
Hopefully this would have helped any one facing problem while implementing this.
Please contact me if you still face any issues and I will try my best to help you.