Wael Assaf Wael Assaf - 4 months ago 19
PHP Question


hello every one hope you enjoy a nice day .
in this example i am trying to filter IPV6 from the input , i tried to input IPV4 in the field in the form , in this case the else statement must be executed , but the condition was true , i mean both IPV4 & IPV6 are true , how can i make that example more specific

code :

$input = $_POST['test'];

$opt = array (

'options' => array (),
'falgs' => FILTER_FLAG_IPV6

if (filter_var($input,FILTER_VALIDATE_IP,$opt) !== FALSE) {
echo 'Good (' . $input . ') is ip version 6';
} else {

echo 'Sorry (' . $input . ') is not ip version 6';

the form :

<form action="checkinput.php" method="post">
<input type="text" name="test">
<input type="submit" value="Send">

thank you for your time


This could definitely be caused by the typo falgs instead of flags in your $opt array. If this isn't just a typo in your question, it would cause the filter_var to ignore the invalid options (this doesn't cause any errors or warnings) and validate using FILTER_VALIDATE_IP with no options, so that either V4 or V6 would work.