zl程序教程

您现在的位置是:首页 >  后端

当前栏目

PHP在不同页面间传递Json数据示例代码

PHP数据JSONJSON代码 示例 页面 不同
2023-06-13 09:15:01 时间
gettest.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;
?>

get.php文件如下:
复制代码代码如下:

<?php
$x=json_decode(stripslashes($_GET["value"]),true);
echourldecode($x["name"]);
echourldecode($x["pass"]);
?>

在IE中输入:http://127.0.0.1:8080/gettest.php

注意:gettest.php,get.php文件的格式utf-8格式。