Question about json transmission between different pages in PHP
Gettest. php:
$ Value ["name"] = urlencode ("myname ");
$ Value ["pass"] = urlencode ("pass888 ");
$ Value ["age"] = 30;
$ Js_value = json_encode ($ value );
$ Url = "http: // 127.0.0.1: 8080/get. php? Id = 100 & value = $ js_value ";
$ Html = file_get_contents ($ url );
Echo $ html;
?>
Get. php:
$ X = json_decode (urldecode ($ _ GET ["value"]);
Echo $ x;
?>
Run: http: // 127.0.0.1: 8080/gettest. php in IE
The result is blank after running. you can print the json data.
Reply to discussion (solution)
Echo $ url in gettest. php; check whether the parameter is correct.
In get. php, json_decode is followed by an object, so echo $ x; is not appropriate.
Urldecode is not required. you can see it by echo $ _ GET ["value "];
Echo $ url in gettest. php; the result is:
Http: // maid: 8080/get. php? Id = 100 & value = {"name": "myname", "pass": "pass888", "age": 30}
In get. php, echo $ _ GET ["value"]; the result is:
{\ "Name \": \ "myname \", \ "pass \": \ "pass888 \", \ "age \": 30}
My goal is to restore jsong string to a json object in get. php and print it out. So I modified the code.
Modify the getp. php code:
$ X = json_decode (urldecode ($ _ GET ["value"]);
// Echo $ _ GET ["value"];
Var_dump ($ x );
?>
Shown as: NULL. This does not seem to work.
I call json_encode in the same PHP file. json_decode is okay. Different pages won't work. I don't know what's going on.
In get. php, echo $ _ GET ["value"]; the result is:
{\ "Name \": \ "myname \", \ "pass \": \ "pass888 \", \ "age \": 30}
Stripslashes instead of urldecode
$ X = json_decode (stripslashes ($ _ GET ["value"]);
Thank you very much.