Skip to content

Instantly share code, notes, and snippets.

@siscia
Created December 27, 2012 22:20
Show Gist options
  • Save siscia/4392612 to your computer and use it in GitHub Desktop.
Save siscia/4392612 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**/
}
}
$a = new phpSecurityClass($dict);
$a->check("ftp", "lalala212`~12lal");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment