How does php submit form forms across domains? This article introduces two methods

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.