Jump to content

get_magic_quotes_gpc Deprecated Function


Recommended Posts

So I have been messing around with a McCodes script a bit, and I saw the function get_magic_quotes_gpc placed all through out the installer. 

I know that this is no longer supported as of PHP 7.4 and was completely removed at PHP 8.0. So I looked around the PHP manual and saw an entry about how to replace that function so that you won't encounter a bunch of Database Error pages along the way. You will have to redo the installation, as far as I know. Edit the installation page by editing the get_magic_quotes_gpc function and replacing it with the new function described here at the PHP Manual.


I recommend reading through this page at #4 which states: 

Here's what I came up with to remove magic quotes from request data.

Replaces two single-quotes with one if magic_quotes_sybase are on, otherwise it just strips slashes.

Note that the `foreach` style makes this work only with PHP 5 and above.


// Strip magic quotes from request data.
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
    // Create lamba style unescaping function (for portability)
    $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
    $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
    $stripslashes_deep = create_function('&$value, $fn', '
        if (is_string($value)) {
            $value = ' . $unescape_function . ';
        } else if (is_array($value)) {
            foreach ($value as &$v) $fn($v, $fn);
    // Unescape data
    $stripslashes_deep($_POST, $stripslashes_deep);
    $stripslashes_deep($_GET, $stripslashes_deep);
    $stripslashes_deep($_COOKIE, $stripslashes_deep);
    $stripslashes_deep($_REQUEST, $stripslashes_deep);


As well as #12 which is the most upvoted response in the manual for this deprecated function:

@ dot dot dot dot dot alexander at gmail dot com

I suggest replacing foreach by "stripslashes_deep":

Example #2 Using stripslashes() on an array on

function stripslashes_deep($value)
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :

    return $value;

This gives:

if((function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc())    || (ini_get('magic_quotes_sybase') && (strtolower(ini_get('magic_quotes_sybase'))!="off")) ){

This has helped me with working on my installer page, and I am currently running through the other files as well. Given that this script is dated and it was written at a time certain functions are now deprecated and completely removed, this script is somewhat redundant. But if you have a passion for the style of the game and a lack of skills to author an original code, you work with what you got.

Any input about this would be appreciated. Any other techniques or references to other sources would be great!

I hope this informed some of you McCodes users.

Kind regards, Matt

Link to comment
Share on other sites


Yeah it frustrated me too because I had to downgrade the PHP version to 7.4 just for the installer to work. So I am working on replacing this and making sure that you don't have to downgrade. I am not sure what smarty or twing is, could you be more specific? Or give me a reference link as to what it is? Thanks!

Edited by Media4um
Link to comment
Share on other sites

if (function_exists("get_magic_quotes_gpc") == false)

    function get_magic_quotes_gpc()
        return 0;
if (get_magic_quotes_gpc() == 0)
    foreach ($_POST as $k => $v)
        $_POST[$k] = addslashes($v);
    foreach ($_GET as $k => $v)
        $_GET[$k] = addslashes($v);

Myself. I just delete the whole lot. from the pages and carry on.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...