php function filter_var($ip, FILTER_VALIDATE_IP) in console giving error [bus error]

I use php function filter_var($ip, FILTER_VALIDATE_IP) to validate an IP. Its working ok when i run it via a http url.

but when i run it via php console it give me error

Bus error

the code is as follows,

$ip = $argv[1];

if (!filter_var($ip, FILTER_VALIDATE_IP)===false)

{

}

else

{
echo 'ip address is not valid';
exit;

}   

echo $ip;

exit;
728x90

2 Answers php function filter_var($ip, FILTER_VALIDATE_IP) in console giving error [bus error]

I upgrade php version from 5.1.6 to 5.6.3 it worked.

3 year ago

i think this is usefull

$ip = $_SERVER['SERVER_ADDR'];
if(!filter_var($ip, FILTER_VALIDATE_IP)===false)
{

}
else
{
    echo 'ip address is not valid';
    exit;
}   
echo $ip;
exit;

3 year ago