Share on Google+Share on Google+

Php Sql Sanitize

Advertisement
This example illustrates how to implement the sanitized filter in php application.

Php Sql Sanitize

This example illustrates how to implement the sanitized filter in php application.

Filter knows two kinds of filter:

  • sanitizing filters
  • logical filters

The sanitizing filters: 

  • Allow or disallow characters in a string
  • Does not care about the data format
  • It always returns a string

 

Source Code of sanitize.php 

<html>
  <head><title>Sanitization</title></head>
  <body>
    <form action="<?=$PHP_SELF?>" method="post" >
      Enter your name: <input name="name">
      <input type="submit" name="submit" value="Go">
    </form>
  </body>
</html>

<?php
  $name="";
  if (!filter_has_var(INPUT_POST, 'submit')) {
    echo "form";
  }
  $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);

  if (is_null($name)) {
    echo "The 'name' field is required.<br />";
  else {
    echo "Hello $name.<br/>";
  }
?>

Download Source Code

 

Output:

Advertisements

Posted on: December 10, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.