Home >Backend Development >PHP Tutorial >How to limit ip address range in php, php limit ip range_PHP tutorial

How to limit ip address range in php, php limit ip range_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 09:58:50918browse

How to limit ip address range in php, php limit ip range

The example in this article describes how to limit ip address range in php. Share it with everyone for your reference. The details are as follows:

Only IP addresses within a limited range 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', '212.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
  return true;
 }
 header('Location: http://www.bkjia.com');
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/976691.htmlTechArticleHow to limit ip address range in php, php limits ip range. This article describes the method of limiting ip address range in php. Share it with everyone for your reference. The details are as follows: Only within a limited range...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn