Php functions that prohibit ip access

Source: Internet
Author: User
Php functions that prohibit ip access
Provide a function to prohibit IP access, including a function that trusts IP access. For more information, see.

The complete code is as follows.

     $ Regs [2]) | ($ ipocts [$ I] <$ regs [1]) {$ result = 0 ;}} else {if ($ maskocts [$ I] <> $ ipocts [$ I]) {$ result = 0 ;}}} return $ result;} function auth_ip () {$ result = 0; $ null_check = 1; $ path = "ip. cf "; // ip address restriction configuration file. the format of each line is/* xxx. xxx. xxx. xxx for example 127.0.0.2xxx.xxx.xxx. [yyy-zzz] for example, 255.0.0.0. [2-23] xxx. xxx. xxx. xxx/nn such as 127.0.0.0/24 */$ fg = @ fopen ($ path, "r"); while ($ line = @ fgets ($ fg, 1024 )) {$ line = trim ($ line); $ line = ereg _ Replace ("#. *", "", $ line); if ($ line! = "") {$ Null_check = 0; if (check_ip ($ line) {fclose ($ fg); return 1 ;}}@ fclose ($ fg ); if ($ null_check = 1) return 1; return $ result ;}?>
Articles you may be interested in: PHP disables IP address access to the website. php disables access from a single IP address or IP address segment.

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.