The problem of transferring JSON between different pages of PHP

Source: Internet
Author: User
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 in IE: http://127.0.0.1:8080/gettest.php
After the run is blank, you should be able to print out the JSON data


Reply to discussion (solution)

You echo $url in the gettest.php; See if the parameters are correct
Get.php is the object after Json_decode, so Echo $x; It's not proper.
Also do not need urldecode, you echo $_get["value"]; You can tell.

Echo $url in the gettest.php; The result is:
http://127.0.0.1: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 get.php in the Jsong string to revert to a JSON object and print it out. So I changed the code.
The getp.php code is modified to:

$x = Json_decode (UrlDecode ($_get["value"));
echo $_get["value"];
Var_dump ($x);
?>

Display Yes: NULL. This doesn't seem to be right.

I call Json_encode in the same PHP file, Json_decode is fine. It's not going to work on different pages, I don't know how.

In get.php, echo $_get["value"]; The result is:
{\ "name\": \ "myname\", \ "pass\": \ "pass888\", \ "age\": 30}

Then you need stripslashes, not urldecode.
$x = Json_decode (stripslashes ($_get["value"));

Thank you so 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.