Php solution to prevent counterfeit data from submitting from URL _ PHP Tutorial

Source: Internet
Author: User
Php prevents counterfeit data from being submitted from the URL. Php prevents counterfeit data from being submitted from the URL. The following code first checks the source of the previous page for the submission of forged data from a URL :? * PHP prevents the non-site data submitted by php from using the URL-based submission method for forged data.

The following code first checks the source of the previous page for the submission of forged data from a URL:

 

This method can only prevent the URL entered manually on the browser bar.

In fact, as long as a hyperlink (www.jbxue.com) is constructed on the server to point to the URL, such as adding a hyperlink to the post and then clicking it, this Check will not work at all.
Currently, it is relatively reliable to transmit important data using the POST method.
You can insert some hidden text into the form to transfer data.
Alternatively, use Ajax to submit data to the server from the client.

/* Create an XHR object */function createXHR () {if (window. XMLHttpRequest) {var oHttp = new XMLHttpRequest (); return oHttp;} // www. jbxue. comelse if (window. activeXObject) {var versions = ["MSXML2.XmlHttp. 6.0 "," MSXML2.XmlHttp. 3.0 "]; for (var I = 0; I <versions. length; I ++) {try {var oHttp = new ActiveXObject (versions [I]); return oHttp;} catch (error) {}}} throw new Error ("Your browser does not support AJAX! ");}/* Use AJAX to pass data to the page */function ajaxPost (url, query_string ='') {var xhr; xhr = createXHR (); xhr. open ('post', url, false); xhr. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = gb2312"); xhr. onreadystatechange = function () {if (xhr. readyState = 4) if (xhr. status! = 200) return;} xhr. send (query_string );}

Bytes. The following code first checks the source of the previous page for the submission of forged data from a URL :? /* PHP prevents the party that submits data outside the site...

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.