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 9149503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:29:09+00:00 2026-06-17T11:29:09+00:00

I’m currently running into a massive wall due to a problem i cannot seem

  • 0

I’m currently running into a massive wall due to a problem i cannot seem to solve.

The problem is that, when you issue a payment through the Facebook payment platform (facebook javascript sdk), it sends data to your callback page, which should handle the payment on the background.

This all works decent, but there is 1 problem: The order ID that facebook uses is a 64bit ID, and my server is a 32bits server, thus it loses precision on the ID when it gets saved to a variable in the callback page. This ultimately results in not being able to get a proper order_ID in the end, because it cannot save the ID.

The issue has been described on several pages on this forum, for example:

facebook credit callback, order_id changes format changes after moving to a new server

and

PHP: Converting a 64bit integer to string

Yet, on both pages there is no solution to the problem, and i cannot seem to fix this myself.
I have tried to convert the json data that facebook sends to my callback page into string data instead of an array with integers (this happens in the basic code provided by facebook), but i just cannot get this to work.

Seeing that others have overcome this problem (without having to migrate everything to a 64bits server), i am wondering how.

Is anyone able to shine a light on this subject?

Edit:
I have tried converting to string, the standard facebook code that gets called to decode the json data (code provided by facebook):

$request = parse_signed_request($_POST['signed_request'], $app_secret);

This calls the function parse_signed_request, which does:

function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);

$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;
}

This function decodes the encrypted json data from facebook (using the app secret) and should decode the json data to a PHP array.

That function uses the following function (the exact:

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

Now, the above code results in the order ID not being saved properly, and it loses its precision, resulting in an id like: 4.8567130814993E+14

I have tried to use the following function to somehow decode the json data into a string (so the 64bit integer ID does not lose its precision), but to no avail:

  function largeint($rawjson) {
    $rawjson = substr($rawjson, 1, -1);
    $rawjson = explode(',' , $rawjson);
    array_walk($rawjson, 'strfun');
    $rawjson = implode(',', $rawjson);
    $rawjson = '{' . $rawjson . '}';
    $json = json_decode($rawjson);
    return $json;
  }


function strfun(&$entry, $key) {
    $data = explode(':', $entry);
    if (FALSE === strpos($data[1], '"')) {
    $data[1] = '"' . $data[1] . '"';
    $entry = implode(':', $data);
    }
}

Edit (Eugenes answer):

If i were to try modifying the JSON data before i use json_decode to make it a php variable, i should be using the preg_replace function?
Below is an example of the initial JSON data that gets sent to the callback page to initiate the payment process.
Here you can already see what the problem is (this is after using json_decode, the id and other data lose their precision). The ID’s are modified to not reflect any real data.
If you compare the buyer ID on the top and user id on the bottom, you can see precision is lost.

Array
(
[algorithm] => HMAC-SHA256
[credits] => Array
    (
        [buyer] => 1.0055555551318E+14
        [receiver] => 1.0055555551318E+14
        [order_id] => 5.2555555501665E+14
        [order_info] => {"item_id":"77"}
        [test_mode] => 1
    )

[expires] => 1358456400
[issued_at] => 1358452270
[oauth_token] => AAAH4s2ZCCEMkBAPiGSNsmj98HNdTandalotmoredata
[user] => Array
    (
        [country] => nl
        [locale] => nl_NL
        [age] => Array
            (
                [min] => 21
            )

    )

[user_id] => 100555555513181
)

Edit #3:

I have tried the following to make all the integers in the JSON data seen as strings, but that results in an error from the facebook platform. It does however change the integers to a string, so i do not lose precision (too bad nothing else works now xD)

preg_replace('/([^\\\])":([0-9]{10,})(,|})/', '$1":"$2"$3', $a)
  • 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-06-17T11:29:10+00:00Added an answer on June 17, 2026 at 11:29 am

    Which version of PHP are you running?

    If you are running a version of PHP that supports the JSON “JSON_BIGINT_AS_STRING” option, that may be your answer. You may have to modify their library wherever json_decode is being used to add that option. See http://php.net/manual/en/function.json-decode.php

    If your PHP version does not support JSON_BIGINT_AS_STRING, then your options are limited to:

    The hacky option: Do some kind of regex operation on the JSON string as it comes back from the FB API and wrap that big ints in double-quotes, so that they decode as a string and not a big int.

    The ideal option: Bite the bullet and migrate to a 64 bit environment. It will save you from a lot of headaches in the long run.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported

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.