dongyo7931 2016-11-17 19:45
浏览 18

使用CURL将2个字符串从一个PHP文件传递到另一个PHP文件

My first.php file

$statusString = "u=10000;t1=1479409;s=10;r=-33;v=3.68;";
$macaddress= "10000";
$url = 'second.php';
$fields = array(
    'newFormat'=>urlencode($statusString),
    'MACAddress'=>urlencode($macaddress)
   );
$fields_string = '';
foreach($fields as $key=>$value) 
{ 
    $fields_string .= $key.'='.$value.'&'; 
}
rtrim($fields_string,'&');
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);   
curl_close($ch);

Here I am trying to send data from my first.php to my second.php

My second.php file

if (isset($_GET['newFormat']))
{ 
    $str = $_GET['newFormat'];
}
else 
    $str = 'no data';
if (isset($_GET['MACAddress']))
{ 
    $macAddress = $_GET['MACAddress'];
}

Here I am trying to retrieve the data sent by first.php.

My first.php invokes second.php, but second.php cannot retrieve any data. In my second.php, $str turn out to be 'no data' as in the the else part and $macAddress is empty! Can anyone please help me solve this?

  • 写回答

1条回答 默认 最新

  • dsf4s5787 2016-12-09 16:25
    关注

    In second.php, should be using _POST and not _GET

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器