开发者

Working with FORM

I'm beginner who try to create Facebook App. Here is the code:

<?php
 $app_id = "xxx";
 $canvas_page = "https://apps.facebook.com/xxx/";

 $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=user_birthday";

 $signed_request = $_REQUEST["signed_request"];
 list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
 $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

 if (empty($data["user_id"])) {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
 } else {
        echo ("<p>Welcome. Your Facebook ID is " . $data["user_id"] . "</p>");

        if (isset($_POST['salary'])) {
            echo "<p>You wrote salary: " . $_POST['salary'] . "</p>";
        }
        else {
            echo "<p>You didn't wrote salary.</p>";
        };

     开发者_运维百科   echo "<form method='post' action='$canvas_page'>";
        echo "<input type='text' name='salary'>";
        echo "<input type='submit'>";
        echo "</form>";
 }
?>

Why the result always show "You didn't wrote salary".


That code does actually work on my canvas, so the problem must be with the auth url. Briefly: if this condition:

if (empty($data["user_id"]))

gets to be true, what you will have will be the user redirected to the auth url and after that back to your canvas page.

You can check if this happens looking at the url: if there is a code=something attached to the end of the url it means that the user has been redirected, doing this obviously you lose the while _POST content.

You could just in case have a print_r or var_dump of $data to be sure that it is actually filled with something.

Bye =)

EDIT 14.10.11: Actually your code is right, there's nothing wrong in it, so the sample code is your own code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜