I want to decode and use an base64 encoded array in php my code looks like this:
<?php
$hash = "YXJyYXkoInNhbXBsZV9pZCI9PiJObnJ5amZCV0p0STllalNRcnE2NHZIejFjc084RnVqUHRGRGk5WkdtM0Z3Vm9ieHprOSIsICJ4eF94eF94eHhfeHh4MSI9PiIwIiwgInNhbXBsZTIiID0+IjAiKQ==";
$hash_decoded = base64_decode($hash);
$all_infos = $hash_decoded;
$sample_id = $all_infos['sample_id'];
$xx_xx_xxx_xxx1 = $all_infos['xx_xx_xxx_xxx1'];
$sample2 = $all_infos['sample2'];
echo $sample_id; ?>
and the decoded array is
array("sample_id"=>"NnryjfBWJtI9ejSQrq64vHz1csO8FujPtFDi9ZGm3FwVobxzk9", "xx_xx_xxx_xxx1"=>"0", "sample2" =>"0")
I can´t get the infos from the Array. The Console says
PHP Warning: Illegal string offset 'sample_id' in [...] on line 6
PHP Warning: Illegal string offset 'xx_xx_xxx_xxx1' in [...] on line 7
PHP Warning: Illegal string offset 'sample2' in [...] on line 8
a
Where´s the problem? Thank´s for answers.
$all_infos = eval('return '.$hash_decoded);, but this is a very bad idea. Instead, save your array usingjson_encodein the first place, instead ofbase64_encode, and save yourself a lot of trouble.