如何将信息从一个站点合并到另一个站点?

时间:2022-11-11 22:44:29

Lets say I have two sites www.a.com and www.b.com. There is a newsletter subscription form on site www.a.com and i need to incorporate that submitted information to site www.b.com and information will be name, address,newsletter format and email id of the subscriber. Is there any way to do so. I am using PHP.

可以说我有两个网站www.a.com和www.b.com。网站www.a.com上有一份新闻通讯订阅表格,我需要将提交的信息合并到网站www.b.com,信息将包括订户的姓名,地址,时事通讯格式和电子邮件ID。有没有办法这样做。我正在使用PHP。

Thanks in advance

提前致谢

3 个解决方案

#1


You can use SOAP, AJAX, XMLRPC and other protocols to pass the data between two sites.

您可以使用SOAP,AJAX,XMLRPC和其他协议在两个站点之间传递数据。

#2


On www.a.com in the page that handles the post data you can do something similar to this:

在www.a.com上处理发布数据的页面中,您可以执行与此类似的操作:

$url = 'www.b.com/sub.php';
$fields = array( 
      'name' => urlencode( $_POST['name'] ),
      'address' => urlencode( $_POST['address'] ),
      'format' => urlencode( $_POST['format'] ),
      'emailid' => urlencode( $_POST['emailid'] )
         );

foreach($fields as $key=>$value) { $query .= $key.'='.$value.'&'; }
rtrim($query,'&');

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, count( $fields ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $query );

curl_exec( $ch );
curl_close( $ch );

Then on www.b.com just handle it like a regular POST request.

然后在www.b.com上就像常规的POST请求一样处理它。


Credit: http://davidwalsh.name/execute-http-post-php-curl

#3


If you just want the two websites to share informations, you have two kind of possibilities :

如果您只是希望两个网站共享信息,您有两种可能性:

  • both have access to the same information at all times
    • for instance, using the same database
    • 例如,使用相同的数据库

    • it is the simplest way, but has drawbacks : the two sites are not independant anymore ; if the DB fails, both sites are down
    • 这是最简单的方法,但也有缺点:两个站点不再独立;如果数据库失败,两个站点都会关闭

  • 例如,两者都可以访问相同的信息,使用相同的数据库,这是最简单的方法,但也有缺点:这两个站点不再是独立的;如果数据库失败,两个站点都会关闭

  • when a modification is done on the data of one website, it is also sent to the other website
    • both sites have a copy of the data (which means if one website is down, the other one can still work)
    • 两个站点都有一份数据副本(这意味着如果一个网站关闭,另一个网站仍可以工作)

    • you need to synchronise the data : when a modification is done on A, A calls a webservice (SOAP, REST, whatever) from B, to tell it "here is the new data for this user" (with some timeout, so that if B is down, A still works)
    • 你需要同步数据:当在A上完成修改时,A从B调用web服务(SOAP,REST,等等),告诉它“这是这个用户的新数据”(有一些超时,所以如果B下来了,A仍然有效)

    • the drawback here is that, one day or another, some data will not be synchronised (because a webservice call has be "lost", or a website has been down for a while) ; so you might need some kind of batch used once per day or week to check the data from both sites.
    • 这里的缺点是,有一天,某些数据将无法同步(因为网络服务呼叫已经“丢失”,或者网站已经停止了一段时间);因此,您可能需要每天或每周使用一次批处理来检查两个站点的数据。

  • 当对一个网站的数据进行修改时,它也被发送到另一个网站,这两个网站都有一个数据副本(这意味着如果一个网站关闭,另一个网站仍然可以工作)你需要同步数据:当对A进行修改时,A从B调用web服务(SOAP,REST,等等),告诉它“这是这个用户的新数据”(有一些超时,所以如果B关闭,A仍然是这里的缺点是,有一天,某些数据将无法同步(因为网络服务电话已“丢失”,或者网站已停机一段时间);因此,您可能需要每天或每周使用一次批处理来检查两个站点的数据。

#1


You can use SOAP, AJAX, XMLRPC and other protocols to pass the data between two sites.

您可以使用SOAP,AJAX,XMLRPC和其他协议在两个站点之间传递数据。

#2


On www.a.com in the page that handles the post data you can do something similar to this:

在www.a.com上处理发布数据的页面中,您可以执行与此类似的操作:

$url = 'www.b.com/sub.php';
$fields = array( 
      'name' => urlencode( $_POST['name'] ),
      'address' => urlencode( $_POST['address'] ),
      'format' => urlencode( $_POST['format'] ),
      'emailid' => urlencode( $_POST['emailid'] )
         );

foreach($fields as $key=>$value) { $query .= $key.'='.$value.'&'; }
rtrim($query,'&');

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, count( $fields ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $query );

curl_exec( $ch );
curl_close( $ch );

Then on www.b.com just handle it like a regular POST request.

然后在www.b.com上就像常规的POST请求一样处理它。


Credit: http://davidwalsh.name/execute-http-post-php-curl

#3


If you just want the two websites to share informations, you have two kind of possibilities :

如果您只是希望两个网站共享信息,您有两种可能性:

  • both have access to the same information at all times
    • for instance, using the same database
    • 例如,使用相同的数据库

    • it is the simplest way, but has drawbacks : the two sites are not independant anymore ; if the DB fails, both sites are down
    • 这是最简单的方法,但也有缺点:两个站点不再独立;如果数据库失败,两个站点都会关闭

  • 例如,两者都可以访问相同的信息,使用相同的数据库,这是最简单的方法,但也有缺点:这两个站点不再是独立的;如果数据库失败,两个站点都会关闭

  • when a modification is done on the data of one website, it is also sent to the other website
    • both sites have a copy of the data (which means if one website is down, the other one can still work)
    • 两个站点都有一份数据副本(这意味着如果一个网站关闭,另一个网站仍可以工作)

    • you need to synchronise the data : when a modification is done on A, A calls a webservice (SOAP, REST, whatever) from B, to tell it "here is the new data for this user" (with some timeout, so that if B is down, A still works)
    • 你需要同步数据:当在A上完成修改时,A从B调用web服务(SOAP,REST,等等),告诉它“这是这个用户的新数据”(有一些超时,所以如果B下来了,A仍然有效)

    • the drawback here is that, one day or another, some data will not be synchronised (because a webservice call has be "lost", or a website has been down for a while) ; so you might need some kind of batch used once per day or week to check the data from both sites.
    • 这里的缺点是,有一天,某些数据将无法同步(因为网络服务呼叫已经“丢失”,或者网站已经停止了一段时间);因此,您可能需要每天或每周使用一次批处理来检查两个站点的数据。

  • 当对一个网站的数据进行修改时,它也被发送到另一个网站,这两个网站都有一个数据副本(这意味着如果一个网站关闭,另一个网站仍然可以工作)你需要同步数据:当对A进行修改时,A从B调用web服务(SOAP,REST,等等),告诉它“这是这个用户的新数据”(有一些超时,所以如果B关闭,A仍然是这里的缺点是,有一天,某些数据将无法同步(因为网络服务电话已“丢失”,或者网站已停机一段时间);因此,您可能需要每天或每周使用一次批处理来检查两个站点的数据。