I have a base64 string:
AgAAOwEwMzEyMTMwMDAwMDAwOTA0QG5haS5lcGMubW5jMTMwLm1jYzMxMi4zZ3BwbmV0d29yay5vcmc=
I can take the raw base64, copy and paste it and run it through bash's base64 -d or php_decode()
and it works. But when I grab the variable from a post using file_get_contents('php://input') in PHP it wont work. However, I can log the JSON encoded post using error_log()
and copy and paste form there and it works. I can echo the base64 value and everything appears normal. But as soon as I wrap base64_decode around the string, I get errors. If it matters, the first two characters of the decoded string is ";0". I thought possibly that may be causing PHP to assume its hex?
Sorry for the messy debug code, but this should illustrate some examples.
$sub_id = get_field($json[$i], "subscriber-id", "null");
error_log("type: " . gettype($sub_id));
error_log("$i raw: |$sub_id|");
$decoded = base64_decode($sub_id);
error_log("$i decoded: $decoded");
error_log("$i raw sub-id: " . $sub_id);
$iccid_a = array();
$raw_sub_id = $sub_id;
$ret = exec("echo \"$raw_sub_id\" | base64 -d ",$iccid_a);
error_log(print_r($iccid_a,1));
I get this output:
type: string
0 raw: |AgAAOwEwMzEyMTMwMDAwMDAwOTA0QG5haS5lcGMubW5jMTMwLm1jYzMxMi4zZ3BwbmV0d29yay5vcmc=|
0 decoded: \x02
0 raw sub-id: AgAAOwEwMzEyMTMwMDAwMDAwOTA0QG5haS5lcGMubW5jMTMwLm1jYzMxMi4zZ3BwbmV0d29yay5vcmc=
Array ( [0] => \x02