Skip to content

Instantly share code, notes, and snippets.

@siscia
Last active December 10, 2015 06:08
Show Gist options
  • Save siscia/4392416 to your computer and use it in GitHub Desktop.
Save siscia/4392416 to your computer and use it in GitHub Desktop.
<?php
$dict = array (
"ftp" => function($input){
if (preg_match("/^([A-Za-z0-9_\-\.])+$/", $input)){
return TRUE;
}else{
return FALSE;
}
}
"url" => function($input){
if (preg_match("/^(http:\/\/|https:\/\/)+([a-zA-Z0-9\.\,\?\'\\/\+&amp;%\$#\=~_\-@\:]*)*$/", $input)){
return TRUE;
}else{
return FALSE;
}
}
"name" => function($input){
if (preg_match("/^([A-Za-z\à\ù\ò\è\é\È\É\Ò\À\Ù\ì\í\Ì\Í\'\s])+$/", $input)){
return TRUE;
}else{
return FALSE;
}
}
/** You get the idea **/
)
class phpSecurityClass
{
public function __construct($dict)
{
$this->dict = $dict;
}
public function check($key, $value)
{
return $this->dict[$key]($value); /** You want to check if $key is a real key of the dict**/
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment