Redirect user to another page when he likes a page tab

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

Index.php

<!doctype html>
<?php
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) {
            header('Location:youlike.php');
        } else {
            echo "you don't like";
        }
?>
<html lang="en" xmlns:fb="https://www.facebook.com/2008/fbml">
    <head>


    </head>
    <body>

    </body>

</html>

youlike.php

You like!

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

Some help would be appreciated once again!

thx

Answers


Try this:

<!doctype html>
<?php

if (!empty($_POST['signed_request'])) {
    list($sig, $payload) = explode('.', $_POST['signed_request'], 2);
    $decoded = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    $liked = $decoded["page"]["liked"];
}

if ($liked) {
    header('Location:youlike.php');
    exit;
}
else {
      echo "you don't like";
}
?>

Need Your Help

Python switch function variant: Keys lambda functions

python dictionary lambda switch-statement

I am working on a simple mapping problem where I have a value where its value falls in a given range, and that range determines the associated label. It is a typical sort of if/else problem, but I ...