PHP Limits IP Address range method, PHP restricted IP range _php Tutorial

Source: Internet
Author: User

PHP Limits IP Address range method, PHP limit IP range


This article explains how PHP restricts the range of IP addresses. Share to everyone for your reference. Specific as follows:

Only IP addresses within a limited scope can be accessed

function get_real_ipaddress () {if (!empty ($_server[' http_client_ip ')) {  return $_server[' http_client_ip '];} ElseIf (!empty ($_server[' http_x_forwarded_for ')) {  return $_server[' http_x_forwarded_for '];} return $_server[' Remote_addr '];}  function In_ip_range ($ip, $ip _one, $ip _two = False) {if (! $ip _two) {  return $ip _one = = = $ip;} return Ip2long ($ip _one) *-1 >= ip2long ($IP) *-1 && ip2long ($ip _two) *-1 <= ip2long ($IP) *-1;} function Validate_ip () {$ip = explode (': ', get_real_ipaddress ()); $ip = $ip [0]; if (In_ip_range ($ip, ' 212.76.229.115 ', ' 21 2.76.229.120 ') {  return true;} else if (In_ip_range ($ip, ' 194.78.4.66 ', ' 194.78.4.79 ')) {  return true;} else if ( In_ip_range ($ip, ' 194.8.4.78 ', ' 194.8.4.78 ')) {  return true;} else if (In_ip_range ($ip, ' 0 ', ' 1 ')) {//local  Retu RN true; } header (' location:http://www.bkjia.com ');}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/976691.html www.bkjia.com true http://www.bkjia.com/PHPjc/976691.html techarticle PHP Limits IP address range methods, PHP restricted IP range This article describes how PHP restricts the range of IP addresses. Share to everyone for your reference. Specific as follows: Only within limits ...

  • Related Article

    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.