php.htaccessjoomlaphp-inimagic-quotes-gpc

Manually disable magic quote in joomla


So looks like I already got 2 down-votes for this thread. This thread can help people with poor understanding on Joomla or other PHP driven CMS as it helped me.

The issue I had, which had been solved by @Gadoma in this thread, was I couldn't output any HTML contents using HTML Module in Joomla since it was automatically adding quotes and slashes while I tried to update links and images in the anchor tags and img tags. This was happening to me because php's Magic Quote was turned on for some reasons.

Who actually faces this type of problem?

In short, people with share hosting and PHP or CMS driven websites actually face this kind of weird issue as they don't have access to the root of their server to modify the .htaccess and php.ini file in order to disable magic quote.

What type of solutions I wanted to get? And why?

I tried almost all the solutions found in the web including this site. I'm not sure why it didn't work for me although some people had positive reply to the solutions. But as I got tired of searching ways to disable the Magic Quote, I wanted to know if there were any way to serve the purpose manually. @Gadoma gave the exact solution I was looking for.

And what was the solution?

If everything fails and you're not a server configuration expert like me, you should be benefited with this thread. Just check out the solution that @Gadoma provided and this issue should go away. I'm going to copy and paste the solution here again,

if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}

Just put the above function at the top of [Joomla Installation Directory]/Administrator/index.php Hope this thread can help someone.


Solution

  • There are numerous ways to disable magic qoutes, check out this post on Joomla site.

    http://docs.joomla.org/How_to_turn_off_magic_quotes_gpc_for_Joomla_3

    or search SO, there are a lot of threads about it.

    If you still cant manage turning off Magic Quotes, you can use this workaround (source - php manual - click here) :

    if (get_magic_quotes_gpc()) {
        $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list($key, $val) = each($process)) {
            foreach ($val as $k => $v) {
                unset($process[$key][$k]);
                if (is_array($v)) {
                    $process[$key][stripslashes($k)] = $v;
                    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset($process);
    }
    

    Put the above function at the top of [Joomla Installation Directory]/Administrator/index.php

    Also take into account that the directive magic_quotes_gps was removed in PHP >= 5.4, so the get_magic_quotes_gpc() will always return false if you run this on PHP >= 5.4.