Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created June 2, 2010 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwlin/422613 to your computer and use it in GitHub Desktop.
Save pwlin/422613 to your computer and use it in GitHub Desktop.
<?php
// filter_input examples
// Make sure it is an integer
$integer = filter_input(INPUT_POST, 'variable_name', FILTER_SANITIZE_NUMBER_INT);
// Make it safe to use in a URL
$url_string = filter_input(INPUT_POST, 'variable_name', FILTER_SANITIZE_ENCODED);
// Make sure it is a valid URL
$url = filter_input(INPUT_POST, 'variable_name', FILTER_VALIDATE_URL);
// prevent XSS
$url = filter_var($url, FILTER_SANITIZE_STRING);
// html encode
$url = htmlentities($url, ENT_COMPAT, 'UTF-8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment