This commit is contained in:
Miles Lott 2001-12-19 20:03:01 +00:00
parent 8d708065f9
commit 561da9b50f

View File

@ -49,89 +49,90 @@
Example1: sanitize('number',$somestring); Example1: sanitize('number',$somestring);
*/ */
/* /*
$GLOBALS['phpgw_info']['server']['sanitize_types']['number'] = Array('type' => 'preg_match', 'string' => '/^[0-9]+$/i'); $GLOBALS['phpgw_info']['server']['sanitize_types']['number'] = Array('type' => 'preg_match', 'string' => '/^[0-9]+$/i');
*/ */
function sanitize($string,$type) { function sanitize($string,$type)
{
switch ($type) switch ($type)
{ {
case "bool": case 'bool':
if ($string == 1 || $string == 0) if ($string == 1 || $string == 0)
{
return True;
}
break;
case "number":
if (preg_match("/^[0-9]+$/i", $string))
{
return True;
}
break;
case "string":
if (preg_match("/^[a-z]+$/i", $string))
{
return True;
}
break;
case "alpha":
if (preg_match("/^[a-z0-9 -._]+$/i", $string))
{
return True;
}
break;
case "ip":
if (eregi("^[0-9]{1,3}(\.[0-9]{1,3}){3}$",$string))
{
$octets = split('\.',$string);
for ($i=0; $i != count($octets); $i++)
{
if ($octets[$i] < 0 || $octets[$i] > 255)
{
return False;
}
}
return True;
}
return False;
break;
case "file":
if (preg_match("/^[a-z0-9_]+\.+[a-z]+$/i", $string))
{
return True;
}
break;
case "email":
if (eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$string))
{ {
return True; return True;
} }
break; break;
case "any": case 'number':
return True; if (preg_match("/^[0-9]+$/i", $string))
break; {
default : return True;
}
break;
case 'string':
if (preg_match("/^[a-z]+$/i", $string))
{
return True;
}
break;
case 'alpha':
if (preg_match("/^[a-z0-9 -._]+$/i", $string))
{
return True;
}
break;
case 'ip':
if (eregi("^[0-9]{1,3}(\.[0-9]{1,3}){3}$",$string))
{
$octets = split('\.',$string);
for ($i=0; $i != count($octets); $i++)
{
if ($octets[$i] < 0 || $octets[$i] > 255)
{
return False;
}
}
return True;
}
return False;
break;
case 'file':
if (preg_match("/^[a-z0-9_]+\.+[a-z]+$/i", $string))
{
return True;
}
break;
case 'email':
if (eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$string))
{
return True;
}
break;
case 'any':
return True;
break;
default :
if (isset($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type'])) if (isset($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type']))
{ {
if ($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type']($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['string'], $string)) if ($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type']($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['string'], $string))
{ {
return True; return True;
} }
} }
return False; return False;
} }
} }
function registervar($varname, $valuetype = 'alpha', $posttype = 'post', $allowblank = True) function registervar($varname, $valuetype = 'alpha', $posttype = 'post', $allowblank = True)
{ {
switch ($posttype) { switch ($posttype)
case "get": {
case 'get':
$posttype = 'HTTP_GET_VARS'; $posttype = 'HTTP_GET_VARS';
break; break;
default : default :
$posttype = 'HTTP_POST_VARS'; $posttype = 'HTTP_POST_VARS';
} }
if (isset($GLOBALS[$posttype][$varname])) if (isset($GLOBALS[$posttype][$varname]))
{ {