The server I'm running my PHP on has "magic_quotes" turned on, so all the input I get (from GET, POST, and cookies) is escaped with backslashes. I don't want this (I handle my own escaping, and I need to be able to work with unescaped strings), but I'm not allowed to change the setting on the server, so I need to figure out a way to "undo" magic quotes.
This code itself works...
$foo = "GLOBALS["_GET"]["test"];
import_request_variables("gp", "in_");
$bar = $in_test;
and I submit the page with "test" set to a'b'c, then $foo will be a'b'c while $bar will be a\'b\'c.
How do I get the stripslashed values into my global variables without having to stripslash each one individually?
This code itself works...
function stripslashes_array($v) {
return is_array($v) ? array_map('stripslashes_array', $v) : stripslashes($v);
}
if (get_magic_quotes_gpc()) {
foreach (array('POST', 'GET', 'REQUEST', 'COOKIE') as $gpc)
$GLOBALS["_$gpc"] = array_map('stripslashes_array', $GLOBALS["_$gpc"]);
}But my problem is that I then want to use import_request_variables to bring any form data into the global variable space, and that's not reflecting the changes I just made to the globals... in other words, if after that code I say:$foo = "GLOBALS["_GET"]["test"];
import_request_variables("gp", "in_");
$bar = $in_test;
and I submit the page with "test" set to a'b'c, then $foo will be a'b'c while $bar will be a\'b\'c.
How do I get the stripslashed values into my global variables without having to stripslash each one individually?
