无法弄清楚为什么我从PHP代码中收到服务器错误

时间:2013-04-15 19:59:57

标签: php facebook plugins registration

在这个PHP页面上,我正在解析我正在使用的facebook注册插件收到的签名请求。我正在保存的已签名请求$ response对象的location属性存在问题,但我无法弄清楚它是什么。我得到两个错误之一:1。地址未被理解,firefox不知道如何打开地址,因为协议与任何程序都没有关联。当我收到该错误时浏览器栏显示: s:18:“纽约,纽约”; 这是我要保存到变量中的location属性的值。第二个错误:在此服务器上找不到请求的URL /~spilot/spilot.koding.com/website/纽约,纽约。再一次,“纽约纽约”,是我试图保存到变量中的位置属性的值。下面是我整个php页面的代码:

<?php

//code omitted here that decodes and checks the JSON signature of the signed request. It has been tested and I know the problem isn't there. 

    if ($_REQUEST) 
    {
    $response = parse_signed_request($_REQUEST['signed_request'],
    FACEBOOK_SECRET);
    }

//this is where I save the values from the registration form into php variables. 

    $name = $response["registration"]["name"]; 
    $email = $response["registration"]["email"]; 
    $password = $response["registration"]["password"];
    $uID = $response["user_id"];

    // The problem is with the location variable. 

//我希望它以字符串形式存储到我的数据库而不是一个对象,这就是我使用// serialize()的原因,但无论是否使用序列化,我都会得到上述错误。

    $location = $response["registration"]["location"]["name"];

    $city = serialize($location);

    ?>

// I'm using the Parse Cloud Server to power the back end and I have to connect with parse using javascript. 

    <script type="text/javascript">

    var password = '<?php echo $password ?>';

    var name = '<?php echo $name ?>';

    var uID = '<?php echo $uID ?>';

    var email = '<?php echo $email ?>';

    var location = '<?php echo $city ?>';

             //Initialize the Parse SDK!


          Parse.initialize("ivHLAO7z9ml1bBglUNuPSgcWabXe3UeE********","gNeGt04lU7xcew8********qc4POVhBsIBSCVj");
               var User = new Parse.User();
                User.set("password",  password);                    
                User.set("username",  name);
                User.set("uID", uID);
                User.set("email", email);
                User.set("location", $city);

          User.signUp(null, { 
          success: function(user) 
          { 
          alert("User signed up!"); 


          } 
          });

    </script>

1 个答案:

答案 0 :(得分:1)

我建议改变这个:

var location = '<?php echo $city ?>';

或许

var city = ...

您的错误表明这被视为等同于

window.location = ...;

由于某种原因,它作为serialize()'字符串来自PHP。由于PHP中的序列化字符串不是有效的URL,因此会出现“未知”协议错误。