不同页面间传递Json数据的php代码
介绍下PHP在不同页面间传递Json数据的代码。1、index.php文件:
<?php
$value["name"]= urlencode("脚本学堂");
$value["pass"]= urlencode("pass888");
$value["age"]=30;
$jsonstr =json_encode($value);
$url="http://127.0.0.1:8080/get.php?id=100&value=$jsonstr";
$html = file_get_contents($url);
echo $html;
//by www.jbxue.com
?>
2,get.php文件
<?php
$x = json_decode(stripslashes ($_GET["value"]), true);
echo urldecode($x["name"]);
echo urldecode($x["pass"]);
//json数据传递
?>
在IE中输入:http://127.0.0.1:8080/index.php
注意:index.php,get.php文件的格式要一致,且均为utf-8格式。
页:
[1]