PHP prevents spoofed data from URL submission Workaround _php tutorial

Source: Internet
Author: User
PHP prevents spoofed data from being submitted from URL methods.

In the case of spoofed data being submitted from a URL, the first one is to check the following code from the previous page source:

 
  /*PHP prevents data from being submitted outside the station */function  checkurl () {$servername=$_server [' server_name '$sub _from=$_server["Http_referer"$sub _len =strlen($servername$checkfrom=substr($sub _ from, 7,$sub _lenif($checkfrom! =$servername)  die ("Warning! You are submitting data from outside! Please terminate immediately! "); }? >

This method only prevents URLs that are entered manually on the browse bar.

In fact, as long as a hyperlink to the URL is constructed on the server (www.jbxue.com), such as when a hyperlink is added to a post, and then clicked, this check will not work at all.
At present, it is more reliable to transmit important data by post method.
You can insert some hidden text into the form to pass the data.
Or, use Ajax to submit data from the client to the server using the following method.

/*Create a Xhr object*/functioncreatexhr () {if(Window.XMLHttpRequest) {varOhttp =NewXMLHttpRequest ();returnOhttp;} Www.jbxue.comElse if(Window.ActiveXObject) {varversions = ["msxml2.xmlhttp.6.0", "msxml2.xmlhttp.3.0"]; for(vari = 0; i < versions.length; i++){Try {varOhttp =NewActiveXObject (Versions[i]);returnOhttp;} Catch(Error) {} }}Throw NewError ("Your browser does not support ajax! ");}/*using AJAX to pass data to page pages*/functionAjaxpost (url,query_string= "){varXHR;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);}

http://www.bkjia.com/PHPjc/819110.html www.bkjia.com true http://www.bkjia.com/PHPjc/819110.html techarticle PHP prevents spoofed data from being submitted from URL methods. In the case of spoofed data being submitted from a URL, the first is a check of the following code from the previous page source:? /* PHP prevents data from being submitted outside the station ...

  • Related Article

    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.