Assume that the IP address range is 192.168.0.0 ~ The code that only allows access to this IP segment is as follows:
Copy codeThe Code is as follows:
<? Php
$ 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:
Copy codeThe Code is as follows:
<? Php
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:
Copy codeThe Code is as follows:
<? Php
If (! ($ From> = 0 & $ to <= 0 ))
Header ('location: http://www.jb51.net/404.html ');
Else
Header ('location: http://www.jb51.net/index.html ');
?>