Re: problem with quotes (single and double) in forms
| From: | Ivo F.A.C. Fokkema | Date: | Thu, 10 Aug 2006 07:36:11 +0000 |
| Subject: | Re: problem with quotes (single and double) in forms | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240447@lists.php.net to get a copy of this message | ||
In case anyone's interested, here's the function I use in the open source
project LOVD to undo Magic Quoting on all GPC arrays:
function lovd_magicUnquote ($var = '')
{
if (!$var) {
if (count($_GET)) {
lovd_magicUnquote(& $_GET);
}
if (count($_POST)) {
lovd_magicUnquote(& $_POST);
}
if (count($_COOKIE)) {
lovd_magicUnquote(& $_COOKIE);
}
} else {
if (is_array($var)) {
foreach ($var as $key => $val) {
if (is_array($val)) {
lovd_magicUnquote(& $var[$key]);
} else {
$var[$key] = stripslashes($val);
}
}
} else {
$var = stripslashes($var);
}
}
}
// You can then just run on all scripts,
// for compatibility regardless of the settings:
if (get_magic_quotes_gpc()) {
lovd_magicUnquote();
}
Typically, I make sure my values are quoted and unquote them when needed,
but I guess that's a matter of preference.
Ivo
On Thu, 10 Aug 2006 13:08:21 +0800, J R wrote:
> here's an improvement jwith recursion:
>
> function stripMagicQuotes(&$var)
> {
> if (get_magic_quotes_gpc()) {
> if(!is_array($var)) {
> $var = stripslashes($var);
> } else {
> array_walk($var, stripMagicQuotes);
> }
> }
> return $var;
> }
>
> hth,
>
> john
> On 8/10/06, Chris <dmagick@gmail.com> wrote:
>>
>> Chris wrote:
>> > Chris wrote:
>> >> J R wrote:
>> >>> try to use this few lines of code.
>> >>>
>> >>> function stripMagicQuotes(&$var)
>> >>> {
>> >>> if (get_magic_quotes_gpc()) {
>> >>> $var = stripslashes($var);
>> >>> }
>> >>> return $var;
>> >>> }
>> >>>
>> >>> this way you don't really have to worry if magic quotes is on or off.
>> >>
>> >> Then he has to modify all the code to call that function ;)
>> >>
>> >
>> > Hmm actually:
>> >
>> > $_POST = stripMagicQuotes($_POST);
>> >
>> > should do it I guess.. not exactly ideal but would work quickly.
>> >
>>
>> Argh, self-replying (*think before hitting send*) :(
>>
>> Of course that function would need a bit more modification but should be
>> able to get it recursive without too many problems.
>>
>> --
>> Postgresql & php tutorials
>> http://www.designmagick.com/
>>