PHP prevents cross domain form submission

  • 2020-11-03 22:04:19
  • OfStack

When writing user registrations,1 must ask whether your form can be submitted across domains.
Solutions in php:
1. In addition to making tables on the page but verifying, the data of the submitted service segment should also be validated.
The main verification codes are as follows:


  $servername=$_SERVER['SERVER_NAME'];// The name of the server host on which the script is currently running. 
  $sub_from=$_SERVER["HTTP_REFERER"];// Link to the front of the current page 1 Of the page  URL  address 
  $sub_len=strlen($servername);// Count the name length of the server. 
  $checkfrom=substr($sub_from,7,$sub_len);// Intercept before submission 1 Of the page url , does not contain http::// Part. 
  if($checkfrom!=$servername){
   $msg=" Incorrect data source! Please submit from this site! ";
   $this->redirect("m_index/reg",$msg);
   exit;
  }

2. Close the registration of this site and log in using development platforms such as Wechat, Weibo and Tencent.
3. Configure the hostlookups parameter in apache. This is based on expendable energy.


Related articles: