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

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

报告相同问题?