Does the PHP check form submission come from this site

Source: Internet
Author: User

Method One:
You can write code that deals with submitting data into a separate file, such as form.php.    
  <?php   
  if    defined (' INSIDE ')    {//to determine whether there is a defined INSIDE constant    
  //processing form    
  }   else   {   
  exit (' ERROR ');    
  }   
  ?>   
     
   Then, on the page that submits the form, define the INSIDE constant, and the constant value doesn't matter    
  define (' INSIDE ',     ' TRUE ');   
    
   Then, to determine whether there is a commit, if submitted, then    
  include    ' form.php ';

======================================================================================= Method two:

<?php 
if (php_version< ' 4.1.0 ') {$_server =  $HTTP _server_vars;}  
if (IsseT ($_server["http_referer"])) { 
//For some browsers may not have http_referer, so make a judgment  
    $ servername=$_server[' server_name ']; 
     $sub _from=$_server["Http_referer"]; 
     $sub _len=strlen ($servername); 
     $checkfrom =substr ($ sub_from,7, $sub _len); 
    if ($checkfrom!= $servername)  
     { 
        echo  "<script language=" JavaScript ' >window.alert (' The data source is wrong, this station does not receive the data from the receiving terminal! '); Window.opener=self;window.close ();</script> "; 
         exit; 
    } 
} 
?> 
     This method is not absolutely safe, Because Http_referer can be forged, can only be a gentleman but can not prevent the villain, but under normal circumstances already enough.

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.