PHP checks whether the IP is legal

不言
Release: 2023-03-24 20:10:02
Original
2079 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


Copy after login


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('.',$ip);

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

        return false;

    }else{

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

            if(($arr[$i] <'0') || ($arr[$i] > '255')){

                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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!