Re: StripSlashes

From: Date: Fri, 11 May 2001 10:33:55 +0000
Subject: Re: StripSlashes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52440@lists.php.net to get a copy of this message
On Thursday 10 May 2001 22:11, Sterling wrote: > H- > > I'd like to be able to strip the slashes from all the imported > HTTP_POST_VARS. > > I found the $string = stripslashes($string); command. > > But this becomes very tedious if I have 20 vars and I need to code each > one with its own stripslashes line. If you set magig_quotes_gpc = off in your php.ini you don't need the stripslashes anymore (just make sure that you use addslashes () on the data before inserting it into the database). > Which I am currently doing in a function. > > So I have two situations. > One: > function scrub_slashes(){ > $email = stripslashes($email); > $first_name = stripslashes(first_name); My method for reading POST data: /* * Get variable <name> from POST request * Automatically strips slashes when needed */ function pbGetPOST ($Name) { global $HTTP_POST_VARS; if (isset ($HTTP_POST_VARS[$Name])) { if (get_magic_quotes_gpc () && is_string ($HTTP_POST_VARS[$Name])) return stripslashes ($HTTP_POST_VARS[$Name]); else return $HTTP_POST_VARS[$Name]; } else { return ""; } } function GetFormData () { $email = pbGetPOST ('email'); $first_name = pbGetPOST ('first_name'); .. } > I'm not sure if I'm doing this function correctly. From what I > understand I think I need to pass each variable to the function; which > would negate the speedyness of my typing which is what I'm going for > anyway. > function scrub_slashes($email, $first_name, etc){ CODE } > > and it'd be called like so $scrub_error = scrub_slashes($email, > $first_name, etc) Hmm, I think someone else answered that already. But another thing I miss in your code is the use of 'global' (See http://php.net/manual/en/language.variables.scope.php) -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) CPU not found. retry, abort, ignore?

« previous php.general (#52440) next »