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

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题