title: How to Read/ Parse Data of Signed_Request from Registration Script in Php 5.1.6
body: <p>I'm trying to implement the Facebook registration script.</p>
  
  <p>The form is getting submitted fine and the server is receiving the signed request. However, it is not able to read/parse the signed request.</p>
  
  <p>I used the script recommended on the registration page <a href="https://developers.facebook.com/docs/plugins/registration/" rel="nofollow">https://developers.facebook.com/docs/plugins/registration/</a> (code below) and all I see for output is:</p>
  
  <p>signed_request contents:</p>
  
  <p>I have verified that the signed_Request is being received. If I pass it to: <a href="http://developers.facebook.com/tools/echo?signed_request=" rel="nofollow">http://developers.facebook.com/tools/echo?signed_request=</a>  I see data. </p>
  
  <p>However on my server with the script below nothing.</p>
  
  <p>The server is http NOT https and using php 5.1.6 (which doesn't have some of the JSON support) Do I need PHP SDK installed? Or the jsonwrapper? I've tried the jsonwrapper but not PHP SDK.</p>
  
  <p>Any help on why the signed_request can not be read would be appreciated.</p>
  
  <p>Code below from facebook</p>
  
  <pre><code>    &lt;?php
      include ('jsonwrapper/jsonwrapper.php');
  
  
      define('FACEBOOK_APP_ID', 'XXX');
      define('FACEBOOK_SECRET', 'XXX');
  
      function parse_signed_request($signed_request, $secret) {
      list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
  
    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);
  
    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
      error_log('Unknown algorithm. Expected HMAC-SHA256');
      return null;
    }
  
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
      error_log('Bad Signed JSON signature!');
      return null;
    }
  
    return $data;
  }
  
  function base64_url_decode($input) {
      return base64_decode(strtr($input, '-_', '+/'));
  }
  
  if ($_REQUEST) {
    echo '&lt;p&gt;signed_request contents:&lt;/p&gt;';
  
    $response = parse_signed_request($_REQUEST['signed_request'], 
                                     FACEBOOK_SECRET);
    echo '&lt;pre&gt;';
    print_r($response);
    echo '&lt;/pre&gt;';
  
  } else {
    echo '$_REQUEST is empty';
  }
  ?&gt; 
  </code></pre>
  
  <p>output is </p>
  
  <p>"signed_request contents:"</p>
  
  <p>If I add: 
   print_r($_REQUEST); to the script I do see the  request but can't parse it</p>