Code summary for disallow single IP and IP segment access in PHP _php tutorial

Source: Internet
Author: User
Prohibit single IP
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 ');
}
$banned _ip = Array (
"127.0.0.1",
"203.0.0.1",
"56.12.50.65",
"192.168.1.88"
);
if (In_array ($userip, $banned _ip))
{
Die ("Your IP was block to connect!");
}
echo "Home test of the script";
?>
Block IP Segments
Copy CodeThe 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 ');
}
$ban _range_low=ip2long ("217.0.0.0"); On the IP segment
$ban _range_up=ip2long ("217.255.255.255");//ip Duan Mei
$ip =ip2long ($userip]);
if ($ip > $ban _range_low && $ip < $ban _range_up)
{
print "banned";
Exit ();
}
?>

http://www.bkjia.com/PHPjc/325701.html www.bkjia.com true http://www.bkjia.com/PHPjc/325701.html techarticle prohibit single IP? PHP//Plus IP access limit if (getenv (' http_client_ip ') strcasecmp (getenv (' http_client_ip '), ' unknown ') {$userip = getenv (' http_client_ip '); } elseif (getenv (' Http_x_fo ...

  • 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.