Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a JSON string as a HTTP query parameter?

On a local version of a project I've been building, I've been sending a JSON string as a HTTP query parameter, and using the json_decode() function to decode the string back into a PHP array.

Locally, this was working fine (XAMPP) however when I upload these files to my clients server, they no longer work. I have diagnosed this as an issue where the parameter for which the JSON string is passed as e.g. o=[{"b_id":"1","p_ref_id":"SHAY899","b_name":"John Smith"}] isn't picked up in the global $_GET array.

I thought perhaps the version of PHP required to encode/decode JSON wasn't available, however I use the json_encode() in other parts of this project, so that can't be the issue. I'm wondering perhaps if it's a max character length issue, and if so how would I solve it (or where would I start at least)?

If not, any other help would be very greatly appreciated!!

like image 320
Kemebear Avatar asked Feb 17 '23 08:02

Kemebear


1 Answers

Use:

$string = urlencode(json_encode($array));

and using the

$array = urldecode(json_decode($string));

to decode the string back into a PHP array.

like image 60
Diogo Baracho Avatar answered Feb 24 '23 05:02

Diogo Baracho