Home  >  Article  >  Backend Development  >  PHP checks whether the IP is legal

PHP checks whether the IP is legal

不言
不言Original
2018-04-26 10:03:452222browse

The content of this article is about PHP checking whether the IP is legal. It has certain reference value. Now I share it with everyone. Friends in need can refer to it

<br/>


No regular judgment is used, just a function written in PHP to verify whether the IP address is legal

function checkIp($ip){
    $arr=explode(&#39;.&#39;,$ip);

    if(count($arr) != 4){

        return false;

    }else{

        for($i = 0;$i < 4;$i++){

            if(($arr[$i] <&#39;0&#39;) || ($arr[$i] > &#39;255&#39;)){

                return false;

            }

        }

    }

    return true;

}

Related recommendations:

Example code for PHP to check whether the website is down

PHP checks whether the content has external links

The above is the detailed content of PHP checks whether the IP is legal. 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