Please do not submit the form repeatedly. Code in PHP that restricts IP segment access and prohibits IP submission of forms.

WBOY
Release: 2016-07-29 08:44:58
Original
1093 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!