-2

In one site, www.example.com, I have a form. It is processed and stored in its database.

Is it possible to send this form data also to another site (www.client-site.com)? It is located on a different server. And this client-site should receive the data and store it on its own database.

I am not sure of the terminology and what should I've been looking for.
Tested different search queries here in SO and this is what most resembles it:
[php] [mysql] +form +"$_post" +external

I'd like to develop this with PHP and the databases run MySQL, and surely security is important in this data transaction.

And hoping this is not a SOAP matter... ;)

Justification:

  • www.example.com runs a mini site of one of my clients
  • www.client-site.com is the client main site
  • being a large company, they cannot provide me credentials to their main site database
  • I have to propose an alternate solution
Community
  • 1
  • 1
brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • What is the need to have replication across two databases? If you're using a web solution like you're thinking are you prepared to have lost data if/when example.com is unable to reach client-site.com? I feel it is better to come up with a replication solution that runs on a schedule. – Grambot Nov 19 '12 at 16:22
  • @TheCapn - I've added context to the question. Thanks for raising the scheduling point. – brasofilo Nov 19 '12 at 16:32
  • 1
    I think that raises more questions. If they are expecting you to interface with their database but are unable to provide a means to do so there are some discussions you need to have I feel. A competent admin should be able to create you a user with limited privileges to do the inserts you require. – Grambot Nov 19 '12 at 17:15

3 Answers3

2

If you have a form hosted on www.example.com like this:

<form method="post" action="http://www.client-site.com/handler.php">
    ...

Then the page http://www.client-site.com/handler.php will be able to access the post variables.

This is why it is important that you validate your post data in your own PHP applications as you can never be sure where the data is coming from and therefore cannot trust it.

Ian Jamieson
  • 4,376
  • 2
  • 35
  • 55
  • Question is that the `post method` should fire two actions and be processed by two handlers. I've added context to my question. Thanks for the input. – brasofilo Nov 19 '12 at 16:34
2

You will need to have something like a webservice (this is the word you are looking for) on site b which you can use from the code within your site a.

SOAP is one possibility to create a webservice, but there are many other possibilities. One is shown in this answer on stackoverflow.

NEVER EVER try to archiv this using forms and something like cURL!

Further you should look for proper authorization on your endpoint (site b) and ensure that ssl is used, as security is important to you.

Community
  • 1
  • 1
yan.kun
  • 6,820
  • 2
  • 29
  • 38
2

I can think of a very ugly solution wich will do the trick :)

   <script language="JavaScript">
function submitForm(theform) {
theform.action = "SITE ONE";
theform.target="myframe1";
theform.submit();

theform.target="";
theform.action = "SITE2";
theform.submit();

}
</script>

<html>
<body>
<form action="" onSubmit="submitForm(this); return false;">
<input type="text" name="userName" value="" />
<input type="Submit" />
</form>
<IFRAME name="myframe1" src="about:blank" width="0"
height="0"></IFRAME>
</body>
</html>

This is not so conventional but will do the trick ! check it out :)

KrisTemmerman
  • 47
  • 2
  • 10
  • Cool trick! I'll test this out in a controlled environment. But I think, for the envisioned setup, I'll follow @yankun's concerns. – brasofilo Nov 19 '12 at 17:43