Last active
August 29, 2015 14:12
-
-
Save 0xMatt/f906cf1d3a1042add9cd to your computer and use it in GitHub Desktop.
$_GET keys whitelist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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