Home  >  Article  >  Backend Development  >  PHP determines whether the IP is intranet

PHP determines whether the IP is intranet

王林
王林Original
2019-09-25 17:55:423647browse

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'];

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;
}

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!

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