0

I have this index.php which tells what to include. I want to have one of the subpages in the tab with fan gating option. Could someone help me and tell me what is wrong with my code? I'm not very into php.

    <?php

require 'src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId' => '262995697152250',
  'secret' => '7ad8d22dc1b0224b4bb226d0085b4063',
));

$user = $facebook->getUser();

if ($user) {
  try {
    $likes = $facebook->api("/me/likes/286599224689000");
    if( !empty($likes['data']) )
        echo "I like!";
    else
        echo "not a fan!";
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array(
    'scope' => 'user_likes'
  ));
}

$signed_request = $facebook->getSignedRequest();

$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];




include ("header.php");
if(!isset($_GET['page'])) $_GET['page']="";
switch($_GET['page']) {
case "1": include('leftside.html'); include('informace.html'); break;
case "2": include('reference.html'); break;
case "3": include('clanky.html'); ;break;
case "4":
// If a fan is on your page
if ($like_status) {
include ("formular.html");
} else {
// If a non-fan is on your page
include ("nonfan.html");}
;break;

case "5": include('clanok1.html'); break;
case "6": include('clanok2.html'); break;
case "7": include('clanok3.html'); break;
case "8": include('clanok4.html'); break;
case "9": include('leftside.html'); include('vyhody.html'); break;

default: include('leftside.html'); include('informace.html');
}
include ("footer.html");
?>
  • If someone who is fan of the FB page where this tab is installed opens the indexphp?page=4 - that _switch case "4"_ than then instead of formular.html the nonfan.html is included. It looks like the conditional isn't working there. – Matej Nuhlicek Sep 04 '12 at 14:33
  • The `signed_request` parameter gets only passed to your app on the initial load into the iframe; on subsequent requests, that occur when the user navigates _inside_ your app, there is no more `signed_request` – and therefor also no more info, that the user liked the page. If you had your error_reporting set to a sensible value (and display_errors too), PHP would’ve told you that itself (so please, do so). Save the data you get from the signed_request into a session, so that you can access it on subsequent requests. – CBroe Sep 04 '12 at 15:11

1 Answers1

0

To pass variables to a page tab you have to use app_data variable which can be decoded with signed_request. See here: passing custom parameters to facebook fan page tab

Community
  • 1
  • 1
Gil Birman
  • 35,242
  • 14
  • 75
  • 119