We only need to add the following code to feedback.php to make a judgment.
Note: The following is just an example code of PHP restricting IP. If you plan to apply it to CMS, please modify it yourself, or if you are using DEDECMS, you can contact this site.
Copy code The code is as follows:
//Add IP access restrictions
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$userip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$userip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$userip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$userip = $_SERVER['REMOTE_ADDR'];
}
//Restrict ip
if ($userip== '27.37.188.128'){
header("location:http://sc.jb51.net");//Jump to this site after being banned
exit;
}
//Restrict ip segment
$ip_arr = explode('.', $userip);
#Restricted ip segment, assuming it is 192.168.*.*
if (!(($ip_arr[0] == '192' && $ip_arr[1]==' 168') )){
header("location:http://sc.jb51.net");//Jump to our material site after being banned
exit;
}else{
header("location:http ://www.jb51.net");//Normal IP will directly access the homepage of this site
exit;
}
?>
The above introduces the code of please do not submit the form repeatedly in PHP to restrict IP segment access and prohibit IP submission of the form, including the content of please do not submit the form repeatedly. I hope it will be helpful to friends who are interested in PHP tutorials.