PHP code for restricting IP segment access and forbidding IP address submission forms _ PHP Tutorial

Source: Internet
Author: User
PHP code used to restrict access to IP segments and prohibit IP address submission forms. Recently, the code for PHP to restrict access to IP segments and prohibit the submission of IP forms has found that a netizen from Yunnan often posted some spam comments on the fire network, because the dede php of www.veryhuo.com restricts access to IP segments and prohibits code from submitting IP forms

Recently, Xiaobian found that a netizen from Yunnan often posted some junk information comments at the customer's house. because of the dededecms architecture of www.bkjia.com, the system itself does not prohibit the IP address function. 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.

Copy to ClipboardReference: [www.bkjia.com] // 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 '];
}
$ Ip_arr = explode ('.', $ userip );
# The restricted ip segment, for example, 192. 168 .*.*
If (! ($ Ip_arr [0] = '000000' & $ ip_arr [1] = '000000 '))){
Header ("http://www.liehuo.org"); // jump to the home address navigation after being disabled
Exit;
} Else
{
Header ("http://www.bkjia.com"); // normal IP directly access the home page
Exit;
}
?>

Recently, Xiao Bian found that a Yunnan netizen often posted some spam comments on www.veryhuo.com because of the DEDE series of www.veryhuo.com...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.