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?

Ba Ta
  • 43
  • 7

1 Answers1

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.

q74
  • 88
  • 8
  • 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 – Ba Ta Sep 17 '18 at 10:46
  • 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 – q74 Sep 17 '18 at 17:35