Code _php tips for restricting IP segment access in PHP, and for preventing IP from submitting forms

Source: Internet
Author: User
We just need to add the following code to the feedback.php to judge it.

Note: The bottom is just a PHP restricted IP instance code, if you intend to apply to the CMS, please modify yourself, or if you are using DEDECMS, you can contact the site.
Copy Code code as follows:

<?php
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"), and/or prohibited to jump to the cloud Habitat Community Station
Exit
}
restricting IP Segments
$ip _arr = Explode ('. ', $userip);
#限制的ip段, assuming it's 192.168.*.*.
if (!) ( ($ip _arr[0] = = ' 168 ' && $ip _arr[1]== ')) {
Header ("Location:http://sc.jb51.net"), and/or prohibited to jump to the cloud Habitat Community material Station
Exit
}else{
Header ("location:http://www.jb51.net");/normal IP direct access to cloud Habitat Community home
Exit
}
?>

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.