0

Using third party service; they are providing webhook services; I have given my url to send the response on my page: Example: https://abcd.com/postback.php

Getting curl response on postback.php; to read the POST data; I am using following code:

$postdata = file_get_contents("php://input");

but not able to read the header & data content.

Sample Response that they are sending:

curl -L -X POST 'https://abcd.com/postback.php' -H 'x-changenow-signature: xcgh123POPI6727kslsldjsd' -H 'Content-Type: application/json' --data-raw '{"status":"finished","payinHash":"31mrEanXyv","payoutHash":"485d8dz","payinAddress":"3Nups0bF","payoutAddress":"1K1LcQSPZVj2dM","fromCurrency":"sol","toCurrency":"btc","amountSend":0.06676453,"amountReceive":0.00010273,"refundAddress":"Bk1qVzc3GULcJQ0NoW4DsepRJHevzAD8ynznEQ1aNzGq","id":"f7bed8a9e4a350","updatedAt":"2022-06-23T11:22:38.728Z","createdAt":"2022-06-23T11:09:56.403Z","expectedReceiveAmount":0.0001024,"isPartner":false}

Please suggest how to get header and data part.

Sachin
  • 111
  • 2
  • 14
  • Does this answer your question? [How do I read any request header in PHP](https://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php) – CBroe Jul 27 '22 at 06:14

1 Answers1

0

The headers are in $_SERVER. Use $_SERVER['HTTP_X_CHANGENOW_SIGNATURE'] to get the x-changenow-signature header.

The data content is in $postdata. Use

$data = json_decode($postdata);

to convert it to an object. Then you can use $data->status, $data->payinHash, etc. to get the fields of the post data.

Barmar
  • 741,623
  • 53
  • 500
  • 612