Cleaning Variables in PHP
09
September
2015

We must clean or sanitize variable before submitting them through web forms in php

Use Below function to clean your variables.

function clean_variable($value) {

       // If magic quotes not turned on add slashes.
       if(!get_magic_quotes_gpc())

       // Adds the slashes.
       { $value = addslashes($value); }

       // Strip any tags from the value.
       $value = strip_tags($value);

       // Return the value out of the function.
       return $value;

}

You can call the above mentioned function as follows :

$cleaned_variable = clean_variable($_POST['your_variable_name']);
  • 1082 View
  • Pin It