Sanitize user input PHP


/ Published in: PHP
Save to your folder(s)

The function returns the "sanitized" version of user input. Use before putting variables into SQL code.


Copy this code and paste it in your HTML
  1. function sanitize($data)
  2. {
  3. $data = trim($data);
  4. {
  5. $data = stripslashes($data);
  6. }
  7. $data = mysql_real_escape_string($data);
  8. return $data;
  9. }
  10.  
  11. //example
  12. $username = sanitize($_POST['username']);

URL: tricksbycinger.blogspot.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.