PDA

View Full Version : escaping characters regardless of server's config?


rabbitdog
Sat 12th May '01, 1:16am
Hi.

I'm trying to develop a script for distribution, and need to have it insert information into a database....

now, here's the question. Since it will be running on multiple servers with unknown php.ini configurations, I need to have it work (escape ",', etc.) regardless of the server's settings for magic_quotes_runtime and magic_quotes_gpc....

Anyone have any ideas on the best way to do this? Specifics are always welcome lol...

TYIA.

Wayne Luke
Sat 12th May '01, 4:47pm
Before inserting: addslashes("text");

After retrieval: stripslashes("text");

Another function you can use is quotemeta();


These are all documented in the PHP manual under string functions.

rabbitdog
Sat 12th May '01, 8:01pm
Thanks....

but won't the characters get double escaped if the server is automatically doing it?

Wayne Luke
Sat 12th May '01, 8:31pm
Not if you force it off like vBulletin does....


// get rid of slashes in get / post / cookie data
function stripslashesarray (&$arr) {
while (list($key,$val)=each($arr)) {
if ((strtoupper($key)!=$key or "".intval($key)=="$key") and $key!="templatesused" and $key!="argc" and $key!="argv") {
if (is_string($val)) {
$arr[$key]=stripslashes($val);
}
if (is_array($val)) {
$arr[$key]=stripslashesarray($val);
}
}
}
return $arr;
}


if (get_magic_quotes_gpc() and is_array($GLOBALS)) {
$GLOBALS=stripslashesarray($GLOBALS);
}
set_magic_quotes_runtime(0);