How to secure input in php

php sanitize form input

How to secure input in php

Sanitizing data means Remove any illegal character from the data. 

In php you need to impliment 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.

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));
}
Top