How to Send Form Data to an External Database and Process It?
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 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.
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.
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 :)
链接地址: http://www.djcxy.com/p/46190.html