PHP code to restrict IP segment access and prohibit IP submission form
Recently, the editor discovered that a netizen from Yunnan often posted some spam comments on Bangkejia. Since www.bkjia.com is a DEDECMS architecture, the system itself does not have the function of banning IPs. I see these spam comments every day. , although it is not much, it makes people feel uncomfortable, so how to limit 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 to ClipboardQuoted content:
[www.bkjia.com]
//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'];
}
$ip_arr = explode('.', $userip);
#Restricted ip segment, assuming it is 192.168.*.*
if (!(($ip_arr[0] == '192' && $ip_arr[1] =='168') )){
header("http://www.liehuo.org");//Jump to Bangke’s home address navigation after being banned
exit;
} else
{
header("http://www.bkjia.com");//Normal IP will directly access the home page of Bangke Home
exit;
}
?>
http://www.bkjia.com/PHPjc/364763.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364763.htmlTechArticlePHP code to restrict access to IP segments and prohibit IP submission forms. Recently, the editor found that a netizen from Yunnan often Liehuo.com published some spam comments. Since www.veryhuo.com is DEDE...