magic_quotes_gpc() leveller





12
Date Submitted Mon. Oct. 9th, 2006 7:04 AM
Revision 1 of 1
Helper serpentskiss
Tags PHP
Comments 2 comments
Here's a little snippet I got from SitePoint that I now use all the time. Add the code below to the start of each script.

Basically, what this does is checks to see if magic_quotes_gpc() is enabled on the server, and if it is, then it gets rid of all the slashes that magic_quotes_gpc() adds to input from $_GET, $_POST and $_COOKIES globals.

It's a good snippet to use, because it negates the bad programming practices that having magic_quotes_gpc() lets you get away with, and means that you don't really on PHP to validate your input; you get to do it all yourself ;-)

if (get_magic_quotes_gpc()) {

        $_GET = array_map('stripslashes',$_GET);

        $_POST = array_map('stripslashes',$_POST);

        $_COOKIE = array_map('stripslashes',$_COOKIE);

}
 

Jon Thompson

Comments

Comments stripslashes_deep
Mon. Oct. 9th, 2006 7:34 AM    Scripter ctiggerf
Comments mqgpc is not bad practice
Mon. Oct. 9th, 2006 8:53 AM    Scripter sehrgut

Voting