tags:

views:

36

answers:

3

Hi, 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.

Thanks in advance

A: 

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

RaYell
A: 

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

$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.


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

Kane Wallmann
Thanks to all of you. Kane here inserting of information into database of site b is done on b. Is it possible to insert data into the table of site b from site a? :)
A: 

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)
    • 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.
Pascal MARTIN