关于POST方式传递数据的问题

pitlane929 pitlane929 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在研究怎么用POST方式传递数据
我想得到的效果是,打开网页a,向一个网页b传递一个字符串
然后在网页b上显示这个字符串。
在网上找到一份代码,是这样的
网页a的代码:
<?php
$uri = "http://localhost/handle.php";
// 参数数组
$data = array (
'name' => 'tanteng'
// 'password' => 'password'
);

$ch = curl_init ();
// print_r($ch);
curl_setopt ( $ch, CURLOPT_URL, $uri );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$return = curl_exec ( $ch );
curl_close ( $ch );

print_r($return);
?>

网页b的代码
<?php
echo 'this is the posted data';
if(isset($_POST['name'])){
if(!empty($_POST['name'])){
echo '您好,',$_POST['name'].'!';
}
}
?>

在我电脑上实验的结果是打开网页b只显示 this is the posted data
而网页a上显示 您好,tanteng!
有谁能给我解释下为什么吗?如果我想让这句话在网页b上显示该怎么做?
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
pitlane929
基础编程 21,889 成员 140,329 内容