How to Turn Off Magic Quotes on Shared Hosting

How to turn off magic quotes on shared hosting?

As per the manual you can often install a custom php.ini on shared hosting, where mod_php isn't used and the php_value directive thus leads to an error. For suexec/FastCGI setups it is quite common to have a per-webspace php.ini in any case.

--

I don't think O (uppercase letter o) is a valid value to set an ini flag. You need to use a true/false, 1/0, or "on"/"off" value.

ini_set( 'magic_quotes_gpc', 0 );   // doesn't work

EDIT

After checking the list of ini settings, I see that magic_quotes_gpc is a PHP_INI_PERDIR setting (after 4.2.3), which means you can't change it with ini_set() (only PHP_INI_ALL settings can be changed with ini_set())

What this means is you have to use an .htaccess file to do this - OR - implement a script to reverse the effects of magic quotes. Something like this

if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) )
{
$_POST = array_map( 'stripslashes', $_POST );
$_GET = array_map( 'stripslashes', $_GET );
$_COOKIE = array_map( 'stripslashes', $_COOKIE );
}

How to turn off magic quotes gpc for Joomla 3?

For MAMP

Steps:

  1. Go to MAMP application >> Preferences (button) >> PHP (tab) >> Choose 5.3.1 or greater >> choose OK.
  2. Go to the MAMP folder >> bin >> php >> php5.3.26 >> conf >> edit php.ini >> add "magic_quotes_gpc = Off" a few lines above "magic_quotes_sybase = Off".
  3. Restart MAMP's servers.


For most mainstream hosting companies running a CGI-Webinterface

Steps:

Create a php.ini or php5.ini file with the following:

magic_quotes_gpc = Off

Put it in your Joomla 3 root. Then change the htaccess.txt in your Joomla 3 root to .htaccess. Add the following lines to the .htaccess file (at the top), don't forget to change php.ini to php5.ini when applicable :

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/myusername/public_html/yourJ3folder
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>

Change "myusername" and "yourJ3folder" to your respective folders. The "/home/myusername/public_html/yourJ3folder" can be found via the Global Configuration:

In Joomla backend > System > System Information > [Directory Permissions], the folder is usually the same as the log directory (but without /logs at the end).



.htaccess for some hosts

For some hosts, add the following to the .htaccess file in the root of your site (for example /home/myusername/public_html/.htaccess)

php_flag magic_quotes_gpc off


Yet Another Solution For Shared Hosts

create a php.ini file at your Joomla! root.
Add this content to the file and save

magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off

Edit your .htaccess file and add this line at the top and save the file

SetEnv PHPRC /home/youruser/public_html/php.ini

Test if the error message goes away

source : How to turn off magic quotes on shared hosting?



Another solution (for the hosts where PHP is running as FCGI module)

Works for PHP 5.3 and higher

create a .user.ini file at your Joomla! root.
Add this content to the file and save

magic_quotes_gpc = Off

SRC - https://docs.joomla.org/How_to_turn_off_magic_quotes_gpc_for_Joomla_3

Disabling magic quotes

On my project I use this:

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);
}

I put it in the runtime and it works.

I also know how to disable it via .htaccess.

php_flag magic_quotes_gpc off

I am sure these both work.

How can I disable PHP magic quotes at runtime?

Only magic_quoted_runtime can be disabled at runtime. But magic_quotes_gpc can’t be disabled at runtime (PHP_INI_ALL changable until PHP 4.2.3, since then PHP_INI_PERDIR); you can only remove them:

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);
}

For further information see Disabling Magic Quotes.

magic_quotes_gpc off on sharehosting with $_POST Array

I usually run this on initialization:

// attempt to disable 'magic quotes' at runtime
@ini_set('magic_quotes_runtime', 0);
@ini_set('magic_quotes_sybase', 0);

// strip slashes if that didn't work
if(get_magic_quotes_gpc()){
function _strip_slashes_ref(&$var){
$var = stripslashes($var);
}

array_walk_recursive($_POST, '_strip_slashes_ref');
array_walk_recursive($_GET, '_strip_slashes_ref');
array_walk_recursive($_COOKIE, '_strip_slashes_ref');
array_walk_recursive($_REQUEST, '_strip_slashes_ref');
}

Magic quotes are removed in 5.4, so you might want to do this only if:

version_compare(PHP_VERSION, '5.4.0') < 0

Why isn't disabling magic quotes in php.ini taking effect?

Note: As of php 7.4 this option is deprecated and it is removed in php 8.0


You could try it with a .htaccess file. You will need this line:

php_flag magic_quotes_gpc Off

As GoDaddy Shared Server doesn't accept this above option try this instead:

You have to make a file named like php5.ini and place this in the root folder. You can add just only the three lines you need or you can copy the php.ini file that you have on your local computer and edit the changes you want.



Related Topics



Leave a reply



Submit