Php simply blocks access from users of specified ip segments. phpip_PHP tutorial

Source: Internet
Author: User
Php simply blocks access from users of specified ip segments. Php simply blocks access from users of specified ip segments, during this time, phpip always shows frequent requests from users of unknown browsers and operating systems in the statistics tool, and the ip addresses are all in php to shield access from users of specified ip segments.

During this time, the statistical tool always saw frequent requests from users of unknown browsers and operating systems, and the ip addresses were all in one segment, which gave me some questions, are these users valid users. There is no browser or operating system record for website access. after several days of analysis, I confirm that these accesses are not accessed by people, but by machines or by others, there was an idea of blocking this ip address.

Export the user data that is not recorded by the browser in the statistics. it is no longer realistic to block more than one hundred ip addresses, however, it is easy to see that these ip addresses are concentrated in some ip address disconnections. Trying to block users in the entire ip segment may lead to some false positives, but it can ensure that the website traffic is clean.

Okay, I won't talk about it anymore. The following describes my implementation ideas and code.

I want to block the first and second ends of the ip address segment 111.11.11.11. I want to block access from multiple ip address segments starting with 111.11.

My implementation idea is to put the ip address set to be blocked in an array and then use the obtained user's ip address to match in the array. if the ip address is not included in the array, the ip address will be released.

For food, I wrote a very rough function.

/*** Shield IP segment */function killIp ($ ip) {$ return = false; $ ip1 = array ('20160301', '20160301', '20160301 ', '20140901'); $ 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 all the content of this article. I hope you will like it.

During this period of time, the statistical tool always saw frequent requests from users of unknown browsers and operating systems, and the ip addresses were all in one...

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.