0

I have a Facebook Tab that is fan-gated using the below code:

<?php
  require 'facebook.php';

  $app_id ="APP_ID";
  $app_secret ="APP_SECRET";
  $facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
  ));

  $signed_request = $facebook->getSignedRequest();
  $like_status = $signed_request["page"]["liked"];

?>

<?php if ($like_status) { ?>



  <?php } else { ?>

    Page overlay hides page content for non-fans.

<?php } ?>

Page content here...

The app lets the user submit a form using method="post". When the form is submitted the page is reloaded and a success-message is shown instead of the form. The URL does not change.

The problem however is that when the form is submitted the page overlay is visible even though the page is liked.

The like gate works perfectly fine for showing/hiding the overlay for the page before the form is submitted.

Any help will be greatly appreciated. Thanks.

Best, Alexander

mrcarlsen
  • 13
  • 2

2 Answers2

0

The signed_request is only passed to your application the first time it is loaded into the iframe.

In order to persist this value, you'll need to save it to a session variable.

What you could do is append a parameter to the form for a user that has already "liked" the URL such that the server, when parsing the form will be able to know if that user "liked" the URL or not.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • Thank you for the answer. Can you give me an example of how to append such a parameter to the form? Thank you :) – mrcarlsen Jul 07 '14 at 13:04
  • @mrcarlsen - you can use a `hidden` input field. You would need to insert the value to the input after the page loads - for that you'd need some JavaScript (but this is already a different question) – Lix Jul 07 '14 at 13:14
0
<p>Hey, check out my fiddle, should give you a big help.</p>

http://jsfiddle.net/972NF/

Adam G
  • 357
  • 2
  • 6
  • 20