PHP Developers Network
http://forums.devnetwork.net/

removing slashes from magic quotes gpc
http://forums.devnetwork.net/viewtopic.php?f=50&t=74859
Page 2 of 2

Author:  Mordred [ Mon Apr 21, 2008 8:01 am ]
Post subject:  Re: removing slashes from magic quotes gpc

Sam, your code is wrong:

It's missing $_COOKIE.
It's recursive.
It's using array_walk_recursive() despite that it's recursive.
It's missing checks for other magic_quote behaviour settings.
It's using foreach.

Some of these things affect the other proposed solutions as well. I'm amazed noone has come with the One Correct Solution To End All Solutions yet.

Author:  Ambush Commander [ Wed Apr 23, 2008 8:46 am ]
Post subject:  Re: removing slashes from magic quotes gpc

If I remember correctly, it's easy enough to fix magic_quotes_gpc for a flat array. From there, it gets a little wanky; it varies between PHP4 and PHP5, as well as whether it's top-level or not.

Author:  Verminox [ Fri May 02, 2008 2:29 pm ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  Jenk [ Mon May 19, 2008 9:00 am ]
Post subject:  Re: removing slashes from magic quotes gpc

You don't need to use the global keyword. $_GET/POST/etc. arrays are already super globals.

Author:  Verminox [ Fri May 23, 2008 4:35 am ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  Jenk [ Fri May 30, 2008 12:32 pm ]
Post subject:  Re: removing slashes from magic quotes gpc

Then why not just do:
Syntax: [ Download ] [ Hide ]
$arrays = array( $_GET, $_POST, $_REQUEST, $_COOKIE );

Author:  Benjamin [ Fri May 30, 2008 3:31 pm ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  Verminox [ Sat May 31, 2008 7:22 am ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  matthijs [ Sat May 31, 2008 7:57 am ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  Benjamin [ Sat May 31, 2008 9:35 am ]
Post subject:  Re: removing slashes from magic quotes gpc


Author:  s.dot [ Mon Feb 18, 2013 6:12 am ]
Post subject:  Re: removing slashes from magic quotes gpc

Oh, wow. Is there a rule here against rehashing old threads?

I came back to this thread because I was working on a new project that had a similar function but didn't do it recursively and I wanted to update it with mine. Then I found the function I'm using on a different project.

Anyways, I've been using this for a long time (since after this thread I started, obviously).

Syntax: [ Download ] [ Hide ]
function func_stripGPC($arr)
{
        if (is_array($arr))
        {
                foreach ($arr AS $k => $v)
                {
                        $arr[$k] = func_stripGPC($v);
                }
        } else
        {
                $arr = stripslashes($arr);
        }
               
        return $arr;
}

$magicQuotesGPC = function_exists('get_magic_quotes_gpc') ? get_magic_quotes_gpc() : false;
$magicQuotesSybase = (bool) strtolower(ini_get('magic_quotes_sybase'));

if ($magicQuotesGPC || $magicQuotesSybase)
{
        foreach (array('_GET', '_POST', '_COOKIE') AS $sg)
        {
                ${$sg} = func_stripGPC(${$sg});
        }
}


My question is, doesn't this handle arrays within arrays.. such as multidimensional arrays in post? I assume that it does because it's recursive so I don't understand a few posts above. Also, is there still the apache bug (i assume it's a bug, if not a limitation) where 510+ levels will crash it?

Author:  Benjamin [ Mon Feb 18, 2013 8:54 am ]
Post subject:  Re: removing slashes from magic quotes gpc

Yeah this post contains information that's out of date.

Page 2 of 2 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/