Sometimes, for the sake of website security, we cannot directly submit form data across domains. what if we have this requirement? Next we will introduce two cross-origin methods to solve direct cross-origin problems. let's take a look at two php cross-origin form submission methods. 1. pass... sometimes, for the sake of website security, we cannot directly submit form data across domains. what if we have this requirement? Next we will introduce two cross-origin methods to solve direct cross-origin problems.
Let's take a look at two php cross-origin form submission methods.
1. use php curl
$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://phprm.com",array('name'=>"tank"));
In the past, many people used curl to capture the email address book, but it is no longer possible. haha.
II. use jquery form and 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 success: function (data) {// data save the data returned after submission, it is generally json data // Here you can handle the data alert ('submitted successfully! ') ;}$ (This). resetForm (); // reset the form after submission}); return false; // prevent the form from automatically submitting events });
3. php code
Header ("Access-Control-Allow-Origin: *"); // Cross-Origin permission settings, Allow all headers ("Access-Control-Allow-Origin: http://www.phprm.com "); // only test.com is allowed to submit data across domains