Php ip address-based access control code. Assume that the IP address range is 192.168.0.0 ~ The code that only allows access to this IP segment is 192.168.0.255: Copy the code as follows :? Php $ IP $ _ SERVER [REMOTE_ADDR]; $ fromstrcmp ($ IP, assuming the IP address range is 192.168.0.0 ~ The code that only allows access to this IP segment is as follows:
The code is as follows:
$ IP = $ _ SERVER ['remote _ ADDR '];
$ From = strcmp ($ IP, '192. 168.0.0 ');
$ To = strcmp ($ IP, '192. 168.0.255 ');
If (! ($ From> = 0 & $ to <= 0 ))
Echo "Access Denied ";
Else
Echo "Homepage ";
?>
In the process, this code first captures the visitor's IP address and then determines whether the IP address meets the access conditions. If yes, the page is output normally. otherwise, access is denied.
Therefore, if the user's IP address meets the requirements, you only need to simply output or include a page file. The file contains the following code:
The code is as follows:
If (! ($ From> = 0 & $ to <= 0 ))
Echo "Access Denied ";
Else
Include('homepage.html ')";
?>
Of course, you can also jump to different pages based on the judgment results. The jump code is as follows:
The code is as follows:
If (! ($ From> = 0 & $ to <= 0 ))
Header ('Location: http://www.jb51.net/404.html ');
Else
Header ('Location: http://www.jb51.net/index.html ');
?>
IP address range: 192.168.0.0 ~ The code that only allows access to this IP segment is as follows :? Php $ IP = $ _ SERVER ['remote _ ADDR ']; $ from = strcmp ($ IP ,'...