dqy27359 2015-12-08 16:36
浏览 31
已采纳

如何在PHP中发送POST数据时加载页面

maybe this is sound's stupid but i want to make a page that can give some result when it is being called with a POST data..

lets say i have a.php with post data validation which can receive post data from outer server.

 if ((isset($_POST['authKey'])) && (isset($_POST['cmd'])) && ($_POST['authKey']==$this->key) && ($_POST['cmd']=='hello'))
        {
            if (in_array($_SERVER['HTTP_REFERER'], $this->trusted))
               echo 'hello world';
        }

how to make b.php can get hello world by sending POST data. Thank you.. Sorry my English is so bad.

  • 写回答

1条回答 默认 最新

  • douwen9540 2015-12-08 16:39
    关注

    You can have an HTML FORM on b.php

    <form action="b.pbp" method="post">
      <input name="authKey">
      <input name="cmd">
      <button>Make request</button>
    </form>
    

    You can make an ajax request from b.php

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (xhttp.readyState == 4 && xhttp.status == 200) {
        alert(xhttp.responseText);
      }
    };
    xhttp.open("POST", "b.php", true);
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhttp.send('authKey=x&cmd=y');
    

    You can make a cUrl request on the server side from b.php http://php.net/manual/en/book.curl.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题