Recently, xiaobian found that a netizen from Yunnan often posted some spam comments on the website. Due to the DEDECMS architecture, the system itself does not prohibit IP addresses. Every day, I see these spam comments, although there are not many, but it makes people feel uncomfortable, how can we limit it?
Recently, xiaobian found that a netizen from Yunnan often posted some spam comments on the website. Due to the DEDECMS architecture, the system itself does not prohibit IP addresses. Every day, I see these spam comments, although there are not many, but it makes people feel uncomfortable, how can we limit it?
We only need to add the following code in feedback. php to judge.
Note: The following is only an example code for php ip address restriction. If you want to apply the Code to CMS, modify it on your own. Or if you are using DEDECMS, contact this site.
The Code is as follows:
// Add IP address 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 addresses
If ($ userip = '27. 37.188.128 '){
Header ("location: http:// SC .jb51.net"); // jump to the foot home site after being disabled
Exit;
}
// Restrict ip segments
$ Ip_arr = explode ('.', $ userip );
# The restricted ip segment, for example, 192. 168 .*.*
If (! ($ Ip_arr [0] = '000000' & $ ip_arr [1] = '000000 '))){
Header ("location: http:// SC .jb51.net"); // jump to the script home material station after being disabled
Exit;
} Else {
Header ("location: http://www.jb51.net"); // normal IP directly access the Home Page
Exit;
}
?>