Reputation: 57
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)
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?
Upvotes: 1
Views: 1600
Reputation: 86
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.
Upvotes: 2