Skip to content

Instantly share code, notes, and snippets.

@chtombleson
Created April 6, 2014 02:02
Show Gist options
  • Save chtombleson/10000598 to your computer and use it in GitHub Desktop.
Save chtombleson/10000598 to your computer and use it in GitHub Desktop.
PHP sanitize function.
<?php
function get_param($key, $filter=FILTER_SANITIZE_STRING) {
if (!isset($_GET[$key])) {
return null;
}
return filter_var($_GET[$key], $filter);
}
function post_param($key, $filter=FILTER_SANITIZE_STRING) {
if (!isset($_POST[$key])) {
return null;
}
return filter_var($_POST[$key], $filter);
}
function cookie_param($key, $filter=FILTER_SANITIZE_STRING) {
if (!isset($_COOKIE[$key])) {
return null
}
return filter_var($_COOKIE[$key], $filter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment