2015-12-08 44 views
0

發送POST數據也許這就是聲音的愚蠢,但我想打一個網頁,可以給予一定的結果,當它被稱爲一個POST數據..如何加載頁面,而在PHP

可以說,我有一個.php與後期數據驗證,可以從外部服務器接收發布數據。

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'; 
     } 

如何讓b.php通過發送POST數據可以得到hello world。 謝謝.. 對不起,我的英語太糟糕了。

回答

0

你可以有b.php一個HTML表單

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

您可以從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'); 

您可以從B中的服務器端捲曲請求一個Ajax請求.php http://php.net/manual/en/book.curl.php

+0

也許沒有ajax .. –

+0

使用第一種方法,我只是直接到a.php ..我想要得到回聲給我的變量與一個請求..這可能嗎? –

+0

你有從b.php到a.php的重定向嗎?這可能與阿賈克斯。 – Musa