search
Homephp教程php手册php限制ip地址范围的方法

php限制ip地址范围的方法

Jun 13, 2016 am 09:08 AM
phponlyexistaddresstalentmethodofscopewithin rangeaccesslimit

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

}

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程序设计有所帮助。

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools