How to secure input in php

How to secure input in php

In PhP you need to implement this one for secure input for MySQL. This one also help to know you about your question - How to Write Secure PHP Code to Prevent Malicious Attacks.

Sanitizing data means Remove any illegal character from the data. 

function sanitize_input($string) {
    if (is_string($string)) {
      return trim(sanitize_string(stripslashes($string)));
    } elseif (is_array($string)) {
      reset($string);
      while (list($key, $value) = each($string)) {
        $string[$key] = sanitize_input($value);
      }
      return $string;
    } else {
      return $string;
    }
}
function sanitize_string($string) {
    $patterns = array ('/ +/','/[<>]/');
    $replace = array (' ', '_');
    return preg_replace($patterns, $replace, trim($string));
}
Related posts
Write a comment