Home > Article > Backend Development > PHP checks whether the IP is legal
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('.',$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; }
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!