How to setup a master Facebook tab (app) that displays unique content depending on the Facebook page

We had a client request that we create a Facebook app that can be installed by their customer's pages that would display unique content. This is how we solved the problem.

The Facebook tab would lead to this PHP, which then redirects the viewer to the intended customized content based on the page ID

if(!empty($_REQUEST["signed_request"])){  //if facebook has sent a signed request
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); //turn it into an array
if(!empty($data['page']['id'])){ //if the page id is sent
$find_site = mysqli_query($db_link, "SELECT website_id FROM fb_tabs WHERE page_id='".$data['page']['id']."' LIMIT 1") or die(mysqli_error($db_link)); //get the website id  using the facebook page ID (if doing a multisite web-app) Populate this table by asking the user what page they added the tab to.
$web_id = mysqli_fetch_array($find_site);
$find_site = mysqli_query($db_link, "SELECT * FROM websites WHERE id='".$web_id['website_id']."' LIMIT 1") or die(mysqli_error($db_link)); //grab their website's info
if(mysqli_num_rows($find_site) == 1){
$site_info = mysqli_fetch_array($find_site);
header("location: ".$website_url.$site_info['domain']); //redirect to their site

Shane Stebner

Author: Shane Stebner

Shane is a successful web-developer specializing in responsive design, and the open-source LAMP stack. Over the years, he's gained in-depth experience with Stripe, Twilio, PhantomJs,, PayPal, Facebook, Twitter, and many other plugins/APIs.

comments powered by Disqus