views:

169

answers:

2

Hi,

I'm running this function to sanitize all user input through out my site, but it worries me that it may be very performance intensive...

 // function for cleaning arrays, recursively for arrays held inside arrays
    function array_clean($array)
    {
        // if its an array, walk each element recursively
        if(is_array($array))
        {
         return array_map("escape", $array);
        }

        // until its a single element, then clean the single element
        else
        {
         return escape($array);
        }
    }

    // Recursively walk our global variables
    $_POST= array_map("array_clean", $_POST);
    $_GET= array_map("array_clean", $_GET);
    $_REQUEST= array_map("array_clean", $_REQUEST);
    $GLOBALS= array_map("array_clean", $GLOBALS);
    $_SERVER= array_map("array_clean", $_SERVER);
    $_FILES= array_map("array_clean", $_FILES);
    $_COOKIE= array_map("array_clean", $_COOKIE);
    $_SESSION= array_map("array_clean", $_SESSION);
    $_ENV=array_map("array_clean", $_ENV);

I need your insight.. Thanks

+2  A: 

Don't worry, profile.

Never trust your instinct or anyone's opinion on where performance bottlenecks are, run a profiler and know for sure.

If you need to find a profiler, Xdebug has some pretty good reviews.

Ben S
ok, thanks but do you recommend any one in particular I'm yet to use anyone successfully
Askcat
Just edited to add the suggestion :)
Ben S
A: 

Thanks @ Ben S, I'm checking it out

Askcat