Let's take a look at two ways to cross-domain submit form for PHP
one, through the PHP curl
function Curlpost ($url, $params)
{
$postData = ';
foreach ($params as $k => $v)
{
$postData. = $k. ' = '. $v. ' & ';
}
RTrim ($postData, ' & ');
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,true);
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, Curlopt_post, Count ($postData));
curl_setopt ($ch, Curlopt_postfields, $postData);
$output =curl_exec ($ch);
Curl_close ($ch);
return $output;
}
Echo curlpost ("http://test.com", Array (' name ' => "Tank"));
Before many people use curl to grasp, the mailbox address Book, but now is not OK. Ha ha.
two, using jquery Form,ajax to submit
1, download Jquery.form.js
2,js Code
$ (' #testform '). Submit (function () {
$ (this). Ajaxsubmit ({
Type: ' Post ',//Submit method Get/post
DataType: "JSON",//data type
URL: ' Your URL ',//URL to submit
Success:function (data) {//File returns after submission, typically JSON data
Data can be related to processing here
Alert (' Commit success! ');
}
$ (this). Resetform (); Reset form after submission
});
return false; Prevent forms from automatically submitting events
});
3,php Code
Header ("access-control-allow-origin:*"); Cross-domain permission settings that allow all
Header ("access-control-allow-origin:http://www.test.com"); Only allow test.com to submit data across domains