Hello all
I’m not able to understand which function to believe and use.
For eg.
$email = someuser@somedomain.com;
$validemail = filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL);
if($validemail)
{
echo "email is valid";
}
else
{
echo "email is not valid";
}
This example shows that email is invalid while if I use
$validemail = filter_var($email, FILTER_VALIDATE_EMAIL);
if($validemail)
{
echo "email is valid";
}
else
{
echo "email is not valid";
}
And this one shows that email is valid.
I’m not able to understand how these functions are working so differently.
Are you sending the email address in your first example via POST?
[fphp]filter_input[/fphp]
Gets a specific external variable by name and optionally filters it
If not, the functions are performing perfectly.
The second param for filter_input should be a name of a GET key, rather than a variable:
$email = filter_input(INPUT_POST, ‘email’, FILTER_VALIDATE_EMAIL);
would check if $_GET[‘email’] is valid.
Yupp, I’m sending this information via POST only.
But then I first parse the POST and assign them into the separated variable
like $email = $_POST[‘someuser@somedomain.com’];
and then I tried to validate the email via ‘filter_input’.
Well I think I’m getting the drift here as first I’ve to validate the email directly without assigning into any variable.
Well dunno whatz going wrong in that.
Yeah was thinking the same, that it should be the name of the key instead of variable.
Thanx…