繁体   English   中英

如何从一个站点发送数据并在PHP中的另一个站点上接收数据

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM