Folks,
Been playing around with developing a 'catch all'
convenience function that could be used to properly screen
form input via a browser to a script. We are
ASSuming register globals is OFF and magic quote are OFF. The
function below would be used like:
$user_email = script_param("u ser_email_addr" );
I was working on this a while back and recently
came back to it (some of the logic looks a little suspect
even to me now!). I'd welcome any thoughts or other functions
people are using to screen input!
Thanks!
John
=============== ============
// This function takes a parameter name and checks both GET
// and POST arrays to find the parameter value.
function script_param ($name) {
global $HTTP_GET_VARS, $HTTP_POST_VARS ;
unset ($val);
if (isset ($_GET[$name])) {
$val = $_GET[$name];
$val = stripcslashes($ val);
} else if (isset ($_POST[$name])) {
$val = $_POST[$name];
if (is_string($val )) {
$val = mysql_real_esca pe_string($val) ;
}
} else if (isset ($HTTP_GET_VARS[$name])) {
$val = $HTTP_GET_VARS[$name];
$val = stripcslashes($ val);
} else if (isset ($HTTP_POST_VAR S[$name])) {
$val = $HTTP_POST_VARS[$name];
if (is_string($val )) {
$val = mysql_real_esca pe_string($val) ;
}
}
// clean the data
if (@is_array($val )) {
// scan each value
foreach ($val as $index =$value) {
$value = @trim($value);
$value = htmlspecialchar s($value);
$val[$index] = $value;
}
return($val);
}
$value = @trim($val);
$value = htmlspecialchar s($value);
// return @$val rather than $val to prevent "undefined value"
// messages in case $val is unset and warnings are enabled
return (@$value);
}
=============== =============== =====
--
John
_______________ _______________ _______________ _______________ _______
John Murtari Software Workshop Inc.
jmurtari@follow ing domain 315.635-1968(x-211) "TheBook.Co m" (TM)
http://thebook.com/
Been playing around with developing a 'catch all'
convenience function that could be used to properly screen
form input via a browser to a script. We are
ASSuming register globals is OFF and magic quote are OFF. The
function below would be used like:
$user_email = script_param("u ser_email_addr" );
I was working on this a while back and recently
came back to it (some of the logic looks a little suspect
even to me now!). I'd welcome any thoughts or other functions
people are using to screen input!
Thanks!
John
=============== ============
// This function takes a parameter name and checks both GET
// and POST arrays to find the parameter value.
function script_param ($name) {
global $HTTP_GET_VARS, $HTTP_POST_VARS ;
unset ($val);
if (isset ($_GET[$name])) {
$val = $_GET[$name];
$val = stripcslashes($ val);
} else if (isset ($_POST[$name])) {
$val = $_POST[$name];
if (is_string($val )) {
$val = mysql_real_esca pe_string($val) ;
}
} else if (isset ($HTTP_GET_VARS[$name])) {
$val = $HTTP_GET_VARS[$name];
$val = stripcslashes($ val);
} else if (isset ($HTTP_POST_VAR S[$name])) {
$val = $HTTP_POST_VARS[$name];
if (is_string($val )) {
$val = mysql_real_esca pe_string($val) ;
}
}
// clean the data
if (@is_array($val )) {
// scan each value
foreach ($val as $index =$value) {
$value = @trim($value);
$value = htmlspecialchar s($value);
$val[$index] = $value;
}
return($val);
}
$value = @trim($val);
$value = htmlspecialchar s($value);
// return @$val rather than $val to prevent "undefined value"
// messages in case $val is unset and warnings are enabled
return (@$value);
}
=============== =============== =====
--
John
_______________ _______________ _______________ _______________ _______
John Murtari Software Workshop Inc.
jmurtari@follow ing domain 315.635-1968(x-211) "TheBook.Co m" (TM)
http://thebook.com/
Comment