Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent automatic add slashes while using parse_str

Tags:

php

my hosting server has magic_quotes on . so when i use parse_str, it also add slashes to it. so data gets stored as \\'name .. how do i prevent this.?

like image 865
Hacker Avatar asked Jun 25 '10 11:06

Hacker


2 Answers

// Turn off magic_quotes_runtime
if (get_magic_quotes_runtime())
    set_magic_quotes_runtime(0);

// Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
if (get_magic_quotes_gpc())
{
    function stripslashes_array($array)
    {
        return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
    }

    $_GET = stripslashes_array($_GET);
    $_POST = stripslashes_array($_POST);
    $_COOKIE = stripslashes_array($_COOKIE);
}
like image 118
vertazzar Avatar answered Nov 15 '22 02:11

vertazzar


Use PHP's stripslashes function. http://php.net/manual/en/function.stripslashes.php

I would also consider turning of magic_quotes on the server. if you can't do that then I would recommend switching hosts

like image 40
Lizard Avatar answered Nov 15 '22 00:11

Lizard