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

PHP checks whether the IP is legal

不言
Release: 2023-03-24 20:10:02
Original
2242 people have browsed it

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/>
Copy after login

<br/>

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

function checkIp($ip){
Copy after login
    $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;

}
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template