PHP determines whether the IP is intranet

王林
Release: 2023-02-24 22:10:01
Original
3735 people have browsed it

PHP determines whether the IP is intranet

1. Create a new PHP document and obtain the IP of the access client. Example:

$cip = $_SERVER['REMOTE_ADDR'];
Copy after login

PHP determines whether the IP is intranet

2. Use echo explicitly Output the IP of the current accessing client for debugging

PHP determines whether the IP is intranet

3. Save the above content and check the IP of the current accessing end. For example, in the example it is local (ie intranet) 127.0. 0.1, where "127." is a characteristic string of the intranet IP

PHP determines whether the IP is intranet

4. Use the strpos() built-in function to determine whether the current customer is from the intranet. Example:

if(strpos($cip,'127.')==0){ echo '当前客户来自(内网):'. $cip; }else{ echo '外网用户:'. $cip; }
Copy after login

PHP determines whether the IP is intranet

5. Save the above file, check the final effect, and determine whether the IP comes from the internal network or the external network

PHP determines whether the IP is intranet

##Note: $_SERVER['REMOTE_ADDR'] is used to obtain the client IP

Recommended tutorial:

PHP video tutorial

The above is the detailed content of PHP determines whether the IP is intranet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!