PHP头条
热点:

php限制ip地址范围的方法


 只有在限定范围内的ip地址才能访问

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

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.net');

}

希望本文所述对大家的php程序设计有所帮助。

 

www.phpzy.comtrue/php/23672.htmlTechArticlephp限制ip地址范围的方法 只有在限定范围内的ip地址才能访问 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 function get_real_ipaddress() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_S...

相关文章

    暂无相关文章

PHP之友评论

今天推荐