Skip to content

Instantly share code, notes, and snippets.

@0xMatt
Last active August 29, 2015 14:12
Show Gist options
  • Save 0xMatt/f906cf1d3a1042add9cd to your computer and use it in GitHub Desktop.
Save 0xMatt/f906cf1d3a1042add9cd to your computer and use it in GitHub Desktop.
$_GET keys whitelist
<?php
if(!validate_request()) {
die('you requested data from a $_GET key that is not whitelisted.');
}
echo 'Your request is valid';
function validate_request($additional_keys = array()) {
$keys = array('controller', 'action', 'page');
if(count($additional_keys)) {
$keys += $additional_keys;
}
return !array_filter($_GET, function($data) use ($keys) {
return (!in_array($data, $keys));
}, ARRAY_FILTER_USE_KEY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment