Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6629913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:19:44+00:00 2026-05-25T22:19:44+00:00

I’m trying to implement the Facebook registration script. The form is getting submitted fine

  • 0

I’m trying to implement the Facebook registration script.

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.

I used the script recommended on the registration page https://developers.facebook.com/docs/plugins/registration/ (code below) and all I see for output is:

signed_request contents:

I have verified that the signed_Request is being received. If I pass it to: http://developers.facebook.com/tools/echo?signed_request= I see data.

However on my server with the script below nothing.

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.

Any help on why the signed_request can not be read would be appreciated.

Code below from facebook

    <?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 '<p>signed_request contents:</p>';

  $response = parse_signed_request($_REQUEST['signed_request'], 
                                   FACEBOOK_SECRET);
  echo '<pre>';
  print_r($response);
  echo '</pre>';

} else {
  echo '$_REQUEST is empty';
}
?> 

output is

“signed_request contents:”

If I add:
print_r($_REQUEST); to the script I do see the request but can’t parse it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:19:45+00:00Added an answer on May 25, 2026 at 10:19 pm

    You don’t need the PHP SDK for this. It may make it easier to do this and various other things, but it is not necessary if you want to do the decode yourself.

    Are you sure you actually have a json_decode function? I don’t think it’s usually part of jsonwrapper.php, so I suspect your script is crashing on that function call. You can use the following function as a substitute, just change the call to usr_json_decode and include the following at the bottom of your script:

    function usr_json_decode($json, $assoc=FALSE, $limit=512, $n=0, $state=0, $waitfor=0)
    {
      $val=NULL;
      static $lang_eq = array("true" => TRUE, "false" => FALSE, "null" => NULL);
      static $str_eq = array("n"=>"\012", "r"=>"\015", "\\"=>"\\", '"'=>'"', "f"=>"\f", "b"=>"\b", "t"=>"\t", "/"=>"/");
      for (; $n<strlen($json); /*n*/)
        {
        $c=$json[$n];
        if ($state==='"')
          {
          if ($c=='\\')
            {
            $c=$json[++$n];
            if (isset($str_eq[$c]))
              $val.=$str_eq[$c];
            else if ($c=='u')
              {
              $hex=hexdec(substr($json, $n+1, 4));
              $n+=4;
              if ($hex<0x80) $val .= chr($hex);
              else if ($hex<0x800) $val.=chr(0xC0+$hex>>6).chr(0x80+$hex&63);
              else if ($hex<=0xFFFF) $val.=chr(0xE0+$hex>>12).chr(0x80+($hex>>6)&63).chr(0x80+$hex&63);
              }
            else
              $val.="\\".$c;
            }
          else if ($c=='"') $state=0;
          else $val.=$c;
          }
        else if ($waitfor && (strpos($waitfor, $c)!==false))
          return array($val, $n);
        else if ($state===']')
          {
          list($v, $n)=usr_json_decode($json, $assoc, $limit, $n, 0, ",]");
          $val[]=$v;
          if ($json[$n]=="]") return array($val, $n);
          }
        else
          {
          if (preg_match("/\s/", $c)) { }
          else if ($c=='"') $state='"';
          else if ($c=="{")
            {
            list($val, $n)=usr_json_decode($json, $assoc, $limit-1, $n+1, '}', "}");
            if ($val && $n) $val=$assoc?(array)$val:(object)$val;
            }
          else if ($c=="[")
            list($val, $n)=usr_json_decode($json, $assoc, $limit-1, $n+1, ']', "]");
          elseif (($c=="/") && ($json[$n+1]=="*"))
            ($n=strpos($json, "*/", $n+1)) or ($n=strlen($json));
          elseif (preg_match("#^(-?\d+(?:\.\d+)?)(?:[eE]([-+]?\d+))?#", substr($json, $n), $uu))
            {
            $val = $uu[1];
            $n+=strlen($uu[0])-1;
            if (strpos($val, ".")) $val=(float)$val;
            else if ($val[0]=="0") $val=octdec($val);
            else $val=(int)$val;
            if (isset($uu[2])) $val*=pow(10, (int)$uu[2]);
            }
          else if (preg_match("#^(true|false|null)\b#", substr($json, $n), $uu))
            {
            $val=$lang_eq[$uu[1]];
            $n+=strlen($uu[1])-1;
            }
          else
            {
            return $waitfor ? array(NULL, 1<<30) : NULL;
            }
          }
        if ($n===NULL) return NULL;
        $n++;
        }
      return ($val);
    }
    

    BTW though, this should be very easy to track down using your error log, turning on extra debugging and adding some echo or var_dump statements as necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.