How to display certain page content only to users who have liked our page on Facebook?

Sometimes it would be convenient if we could display portion of our web page only to people who have liked our page on Facebook.

For example, we decide to giveaway five concert tickets to random participants. We can get more recognizable if participants have to liked our page and possible publish that on their profile page. So let’s create example web page that where people can participate after following this procedure:

1. person connects our web site with Facebook

2. person likes our Facebook page

3. person fill out form with his information to participate in giveaway

Firstly we need to create Facebook page for our web site and get URL like this:

https://www.facebook.com/pages/Lemnin/145152362222716

Secondly, we need Facebook application which can be created in a few minutes on Facebook. We will get application id and secret key to use Facebook API.

Our giveaway page will look like this (step 1):

After clicking on Login with Facebook button, we get a nice popup saying what information will this application be able to access:

After user successfully connects our web site (application) with his Facebook profile, we show step 2:

In this step, user has to like our Facebook page, and after that we show him step 3 – final giveaway form:

We automatically fill out name field with information we get through Facebook API. Mind you, step 3 loads via AJAX, because requests to Facebook servers can sometimes be slow and we want to load our page as quickly as possible.

How will we do it?

We will use Facebook’s javascript API which allows us to connect our website with user’s Facebook account and allow them to like our page. As far as i know, we don’t even need server-side scripting to check Facebook Like status, however, user’s can bypass JS-only solution and therefore we will be using client-side javascript in connection with server-side PHP.

1. How to connect to Facebook API with PHP?

Connecting to Facebook API is pretty simple and everything you need is to create new instance of Facebook class and pass it array with your appId and secret key.

It keeps trying to connect to Lemn.in ??
even tough i see the number of current likes (which is right), it keeps connecting to Lemn.IN?
What am i doing wromg??
I’ve only edited the page url in facebook_test.php and Page_ID in get_form.php

Thx for the great post.I am planning to give away freebies to people and I need this “reveal website contents after our facebook page liked” script very much. However, I find that it is not working now.
Would you mind updating the script? I can pay you for doing this.