[英]How to send data from one site and receive it on another in php
我在wordpress網站上的php文件中的單個變量中具有字符串格式的數據。 我想通過不同服務器上的php文件獲取該變量的值。
我想要一種將變量發送到在不同服務器上創建的接收php文件並在此處打印該值的方法。
簡而言之,例如,讓mydomain1.com/send.php中存在需要存儲或顯示在mydomain2.com/receive.php中的數據
但是, 不使用表單 。發送文件中沒有html表單,我也不想這樣做,因為不應該進行重定向。僅在發送文件數據時執行函數執行時才需要傳輸並僅在接收端顯示。
(我嘗試使用cURL找出解決方案。但是,到處都找到了發送數據的代碼,但接收數據又如何,如何捕獲發送的數據並顯示在接收端。)如果還有cURL或表單之外的其他解決方案提交,我將不勝感激。
請盡快提供幫助。
有很多方法可以做到這一點,一種方法是SOAP客戶端/服務器解決方案。
您基本上有2個php文件,其中server1上的一個文件為client.php,而另一台服務器上有一個名為server.php的文件,它將接收服務器1上client.php發送的所有數據...這是一個簡單的源,您需要將腳本中的URL更改為服務器/客戶端URL,以便它可以工作..:
client.php
<?php
//This is the SOAP Client which will call a method on Server 2 with passing some data:
//uri is the location where client.php is located, and "location" is the exact location to the client, including the name "client.php"
$client=new SoapClient(NULL,array("uri"=>"http://localhost/test","location"=>"http://localhost/test/test.php"));
$message=$client->hello("Hello World");
echo($message);
?>
server.php
<?php
//This is the SOAP Server
class server2{
public function hello($data){
return "I received following data: " . $data;
}
}
//the URI here is the location where the server.php is located.
$settings = array("uri"=>"http://localhost/test/");
$s=new SoapServer(null,$settings);
$s->setClass("server2");
$s->handle();
?>
這是一個教程: http : //davidwalsh.name/execute-http-post-php-curl
基本上,您可以使用CURLOPT_POSTFIELDS
發送urlencoded值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.