-2

I am not familiar with Javascript at all. I need to retrieve the value from externalReferralProgram . Which is in json format.

I want to get the value of this and store it in a PHP variable.

const FTXRest = require('./');

const ftx = new FTXRest({
  key: 'apikey',
  secret: 'apiseceret'
})

ftx.request({
  method: 'GET',
  path: '/api_key_status'
}).then(console.log);
dale landry
  • 7,831
  • 2
  • 16
  • 28
  • 1
    Does this answer your question? [How do I pass JavaScript variables to PHP?](https://stackoverflow.com/questions/1917576/how-do-i-pass-javascript-variables-to-php) – CodeBug Dec 13 '20 at 06:48

2 Answers2

1

PHP is a server-side language. Javascript is a client side language.

What happens is PHP will run whatever stuff its supposed to, then send whatever HTML and javascript you tell it to send to the browser. At this point, PHP will wipe out this session and start handling other requests. The browser then receives this content and starts running the javascript.

With this understanding, you can see that it really doesn't make sense to store a javascript value in a PHP variable - by the time the javascript is running, PHP has already long-forgotten about this request.

Your best bet is to either find a way to do the same javascript logic in PHP, or, make the javascript send a REST request back to the PHP server with whatever data you need, so that PHP can do further processing on it (this means creating a separate PHP file that'll receive javascript data from $_GET or $_POST).

Scotty Jamison
  • 10,498
  • 2
  • 24
  • 30
-1

Use json_decode

Takes a JSON encoded string and converts it into a PHP variable.

PHP Guru
  • 1,301
  • 11
  • 20