Loading Gif

How to detect if someone likes your facebook page

07Sep2012

How to detect if someone likes your facebook page

Please note that recent changes to facebook mean that it is no longer possible to detect whether someone has liked your page using this method.

Right, here is a little class I wrote a few years ago now, but when it comes to facebook apps and custom pages its worth its weight in gold.

How many times have you seen those apps that won’t let you get to the juicy content until you like the page? Annoying! But clients love it.

Here is how you achieve it. (Remember this will only work on apps and custom pages within facebook and dosn’t require the sdk or the user to connect to your app.)

The facebook class

Usage

How it works

As you will notice the php class above gets all the info it needs from the ‘signed_request’ variable.

This ‘signed request’ is sent to every facebook app and page on facebook and includes all kinds of goodies including whether the current logged in facebook user has liked your page.

Essentially it is a base64 encoded object, so with a bit of php wizardry and the base64_decode function we now have access to some facebook goodies.

It can also be used to pass variables into your app but ill go into that in another post.