...

View Full Version : Magic quotes?



mothra
07-18-2005, 03:29 AM
edited.

I'd like to know if there is a more elegant way to do this without the IF block and all the repeating setting of variables. I've got some update queries that are pretty big already.

From the manual:



if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST['lastname']);
} else {
$lastname = $_POST['lastname'];
}

Jalenack
07-18-2005, 04:33 AM
Sure you could use some ternary operators:



$lastname = (get_magic_quotes_gpc()) ? $_POST['lastname'] : addslashes($_POST['lastname']);

dumpfi
07-18-2005, 11:27 AM
Have you tried to use a recursive function and add slashes to all variables in $_POST?


function deepAddSlashes(&$var) {
if(is_array($var) || is_object($var)) {
foreach($var as $key => $value) {
$var[$key] = addslashes($value);
}
}
else $var = addslashes($var);
}
if (!get_magic_quotes_gpc()) {
deepAddSlashes($_POST); // add slashes to every variable in $_POST
deepAddSlashes($_GET); // same for $_GET
}
dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum