Bobbo171
02-08-2006, 10:15 PM
In a different forum, I had asked how to secure my mysql queries when using user input, and they replied that this code protects from it.
if(!get_magic_quotes_gpc()){
function traverse ( &$arr )
{
if ( !is_array ( $arr ) )
return;
foreach ( $arr as $key => $val )
is_array ( $arr[$key] ) ? traverse ( $arr[$key] ) : ( $arr[$key] = addslashes ( $arr[$key] ) );
}
$gpc = array ( &$_GET, &$_POST, &$_COOKIE );
traverse ( $gpc );
}
The only thing is Im not very familiar with the php in this code and Im having a hard time deciphering it line by line. I know what the script does when its all done, but im not sure what it wants sent to it and im kinda fuzzy as to what a foreach loop is and what all the ampersands are for.
Any help is appreciated, Thanks:)
if(!get_magic_quotes_gpc()){
function traverse ( &$arr )
{
if ( !is_array ( $arr ) )
return;
foreach ( $arr as $key => $val )
is_array ( $arr[$key] ) ? traverse ( $arr[$key] ) : ( $arr[$key] = addslashes ( $arr[$key] ) );
}
$gpc = array ( &$_GET, &$_POST, &$_COOKIE );
traverse ( $gpc );
}
The only thing is Im not very familiar with the php in this code and Im having a hard time deciphering it line by line. I know what the script does when its all done, but im not sure what it wants sent to it and im kinda fuzzy as to what a foreach loop is and what all the ampersands are for.
Any help is appreciated, Thanks:)