How to use filter input in PHP

This article describe about filter_input() Function in PHP.
  • 2621

filter_input() Function

This function gets external variable and filters them. Example getting the input.

For validate the variable form insecure source like input filter_input() function used.

From several sources function can get input.

  • INPUT_ENV
  • INPUT_SERVER
  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_SESSION (Not yet implemented)
  • INPUT_REQUEST (Not yet implemented)
     

Syntax

filter_input(input_type, variable, filter, option)

 

Parameter Description
input_type Required. Define the input type.
variable Required. Define ID of the filter.
filter Optional. Define ID of filter to use.
option Optional. Specifies an associative array of flags/options or a single flag/option.

Example

<html>
<body>
<?php
if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL))
{
echo "E-Mail is not valid";
}
else
{
echo "E-Mail is valid";
}
?>
</body>
</html>

 

Output


pic4.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.