1

i have a device that send POST data to my server. so print_r($_POST) is empty, i can see the data only when i run this

$content = file_get_contents('php://input');
var_dump($content);   

//or i can use:  print_r($content);

i save those to a file and result are some json and BINARY DATA (CHECK IMAGE)SCREENSHOT

if i add code like this json_decode($content,true); i dont see anything

so how can i decode binary or what can i do to decode the json and also see what data is send in binary?

6
  • can you add attachment? Commented Sep 17, 2018 at 0:01
  • u can check now Commented Sep 17, 2018 at 0:04
  • You need to try and search that input to look for a valid structure. Then parse THAT. Might I recommend this? Commented Sep 17, 2018 at 0:08
  • 3
    Is there no documentation for this device? What is it supposed to be sending? What is the HTTP request Content-type header? It should be available in $_SERVER['HTTP_CONTENT_TYPE'] Commented Sep 17, 2018 at 0:11
  • 1
    [Content-Type] => application/octet-stream, application/octet-stream Commented Sep 17, 2018 at 0:18

1 Answer 1

2

If you want to decode binary data inPHP, try the following:

<?php
$binarydata = "\x04\x00\xa0\x00";
$data = unpack('C*', $binarydata);
var_dump($data);

output:

array (size=4)
  1 => int 4
  2 => int 0
  3 => int 160
  4 => int 0

Load your contents from file_get_contents('php://input') to $binarydata and you will get an array of values. You can then apply some logic to extract JSON string and process it.

Sign up to request clarification or add additional context in comments.

2 Comments

array(125) { [1]=> int(121) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(123) [6]=> int(34) [7]=> int(102) ................int(125) [124]=> int(10) [125]=> int(0) } so what to do with those
these are bytes, which are built from bits (8 bits = 1 byte). For example string "enroll", which is what you will probably be looking for is represented by the following: char 101, 110, 114, 111, 108, 108 ascii e n r o l l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.