Take the 2-minute tour ×

I had this block of code working but not anymore...


<!doctype html>
require 'php-sdk/src/facebook.php';
$facebook = new Facebook(array(
            'appId' => '453976824647366',
            'secret' => 'fe86f3b0b34b3ed6eXXXXXX',
            'cookie' => true,

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

        if ($liked) {
        } else {
            echo "you don't like";
<html lang="en" xmlns:fb="https://www.facebook.com/2008/fbml">





You like!

It always displays "you don't like", seems it never goes into youlike.php

Some help would be appreciated once again!


share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Try this:

<!doctype html>

if (!empty($_POST['signed_request'])) {
    list($sig, $payload) = explode('.', $_POST['signed_request'], 2);
    $liked = $decoded["page"]["liked"];

if ($liked) {
else {
      echo "you don't like";
share|improve this answer
thanks for your help –  Arnaud Ad Sep 10 '12 at 9:38
@arn - so the problem was that you didn't have the call to exit()? –  Lix Sep 10 '12 at 9:43
probably, at least it seems to work now! thank you again –  Arnaud Ad Sep 10 '12 at 10:06
I have just some problems to understand the meaning of the first lignes in the first "if". Maybe you could develop a bit for me ? thx –  Arnaud Ad Sep 10 '12 at 10:39
If you open a custom tab then Facebook makes a POST request to your app that has details about the user in encoded and signed (so you know it really is Facebook who is running your app in iFrame) format. You could use Facebook app to decode these (like you do in your own script) or if you don't care you can just decode manually and ignore the signature. More info about the signed request format can be found from Facebook docs: developers.facebook.com/docs/authentication/signed_request –  Justus Sep 10 '12 at 10:57
add comment

Because you are in an iframe, you'll need to perform the redirect on the top most frame.

Try this JavaScript -

top.location.href = "youlike.php";

With php you could simply echo out the code like this -

echo '<script type="javascript">';
echo 'top.location.href = "'.$youlike.'";';
echo '</script>';

Depending on the complexity of your pre/post like pages, you might want to simply have all the content on one page and only display certain parts of it if the user "likes" the page.

if ($liked) {
  // place like post page HTML here
} else {
  // place like pre page HTML here
share|improve this answer
I tried the second code you have... this is not working for me actually :( I just put it instead of header('Location:youlike.php'); –  Arnaud Ad Sep 7 '12 at 16:16
@arn - are you getting any errors? In the javascript or php? –  Lix Sep 7 '12 at 16:18
no errors, just displaying nothing –  Arnaud Ad Sep 7 '12 at 16:19
can you see the javascript code on the page? is it in the right place? You could try place an alert() there to see if the code is in fact being executed... –  Lix Sep 7 '12 at 16:20
you can see what it gives here : facebook.com/Luthe131/app_453976824647366 –  Arnaud Ad Sep 7 '12 at 16:23
show 6 more comments

Your Answer


