Re: Re: Recursion to sanitize user input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi M

I don't understand.  I don't think I'm storing it anywhere.  I have it
looping through all the POST variables.  If it's not an array then the
sanitize function returns a sanitized value.  If it's an array then the
sanitize function calls itself again and again until it finds a single
variable and returns it as a sanitized value.


----- Original Message -----
From: "M. Sokolewicz" <tularis@xxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Friday, October 08, 2004 6:19 PM
Subject:  Re: Recursion to sanitize user input


> Very simple :)
> when recursion happens, you return the sanitized value, but never store
> it ;)
>
> zooming@xxxxxxxxxxx wrote:
>
> > I'm trying to sanitize my user input.  My sanitize function does not
work if
> > I send a variable that's an array.  I'm using recursion to go through
the
> > array.  The example below shows that $_POST['city'] works but
$_POST['user']
> > doesn't work.  The array comes back blank.
> >
> > Anyone see what's wrong with my code?
> >
> > OUTPUT:
> >
> > Array
> > (
> >     [city] => New York
> >     [user] =>
> > )
> >
> > CODE:
> >
> > <?php
> >
> > function sanitize($userInput = '')
> > {
> >     if ( is_array($userInput) )
> >     {
> >         foreach ( $userInput as $key => $value )
> >         {
> >             sanitize( $value );
> >         }
> >     }
> >     else
> >     {
> >         if ( get_magic_quotes_gpc() )
> >         {
> >             return trim( $userInput );
> >         }
> >         else
> >         {
> >             return trim( addslashes($userInput) );
> >         }
> >     }
> > }
> >
> > $_POST['city'] = 'New York';
> > $_POST['user']['firstName'] = 'Bob';
> > $_POST['user']['lastName'] = 'Smith';
> > $_POST['user']['country'] = 'USA';
> >
> > foreach ( $_POST as $key => $value )
> > {
> >  $_POST[$key] = sanitize( $value );
> > }
> >
> > echo '<pre>';
> > echo print_r($_POST);
> > echo '</pre>';
> >
> > ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux