Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/HTML/Sanitize Input

November 18, 2012

Sanitize Input

When designing web applications, it’s important to sanitize data before storing them into the database. I use several PHP built-in functions namely trim, strip_tags, htmlspecialchars, and addslashes to sanitize my forms. This function has become a staple for all my web projects. So, here it is.

function sanitize($in) {
  return addslashes(htmlspecialchars(strip_tags(trim($in))));
}

function sanitize($in) { return addslashes(htmlspecialchars(strip_tags(trim($in)))); }

Whenever I need to sanitize a form input, I simply use the sanitize function before storing the data to the database.

$_POST['firstname'] = sanitize($_POST['firstname']);

$_POST['firstname'] = sanitize($_POST['firstname']);

Filed Under: HTML, PHP Tagged With: input, sanitize

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021