dssjxvbv918586 2014-04-22 11:52
浏览 64
已采纳

发送没有表单的PHP发布数据的简单方法

I have a file called "receive_data.php" on my server, that receives POST data from excel vba constantly throughout the day. This file inserts data into the database as a log of which tools and reports are being used throughout the day for the business I work for.

I have now created a report that is generated onscreen when php file "show_data.php" is viewed.

When show_data.php is viewed, ideally I would like to 'ping' "receive_data.php" with similar values as below:

$_POST['code'] = 1;
$_POST['r_id'] = 24;

The company I work for uses very old browsers, therefore using something like AngularJS is not an option as it can be unreliable in anything older than IE9.

I could include "receive_data.php" within the php file, but it's still a case of being able to have the variables sent in as 'post' variables.

I could modify the "receive_data.php" file to accept variables, however...

Ultimately I do not want to modify "receive_data.php" in any way, if at all possible.

If this is possible, then great! If not, then I will have to look at modifying the file, but due to the business intensive needs, editing it is worse for us.

  • 写回答

1条回答 默认 最新

  • dongshi6844 2014-04-22 11:59
    关注

    You can try something like this:

    if( $curl = curl_init() ) {
        curl_setopt($curl, CURLOPT_URL, '<path_to_your_script>/receive_data.php');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, "code=1&r_id=14");
        $out = curl_exec($curl);
        echo $out;
        curl_close($curl);
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮