Json transmission between different pages in PHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.