PHP Simple implementation masking the user's access to the specified IP segment _php tutorial

Source: Internet
Author: User

PHP Simple implementation Masking user access to specified IP segments


here to share is a simple use of PHP implementation of the mask specified IP segment code, very practical, the need for small partners can refer to the next.

This period of time in the statistics tool always see some unknown browser, unknown operating system users of the frequent requests and IP are in a paragraph, so I have some questions, these users are valid users. Website access No browser does not have a record of the operating system, I after a few days of analysis to confirm that these visits are not people in the access but some machines or other people in the collection of my station, the idea of a shield of this IP.

The statistics inside the user data without browser record to see the next Shield IP is not realistic IP is more than 100, but carefully watch it is not difficult to see that these IP are concentrated in some IP fault. Think of a way to block the entire IP segment of users, may cause some manslaughter but can ensure that the site traffic is clean.

Okay, I'm not talking nonsense. Below is a description of my implementation of the idea and the implementation of the Code

I was thinking of it. Block IP segment of the front end 111.11.11.11 This IP I'm going to block more access to this IP segment starting with 111.11

My implementation of the idea is to block the IP set to be masked in an array and then use the obtained user's IP to match the array, in the array of the mask is not in the array of the release.

Let's serve. I've written a function that's a rough one, don't squirt.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

/**

* 屏蔽IP段

*/

function killIp($ip){

$return = false;

$ip1 = array('111', '112', '102', '114');

$ip2 = array('1', '2', '3', '4', '5');

$temp = explode('.', $ip);

if (in_array($temp[0], $ip1) && in_array($temp[1], $ip2)) {

$return = true;

}

return $return;

}

The above is the whole content of this article, I hope you can enjoy

http://www.bkjia.com/PHPjc/991647.html www.bkjia.com true http://www.bkjia.com/PHPjc/991647.html techarticle PHP Simple implementation masking the user's access to the specified IP segment here to share is a simple use of PHP implementation of the mask specified IP segment code, very practical, the need for small partners can ...

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