Questions tagged [magic-quotes-gpc]

`magic_quotes_gpc` is a PHP configuration setting enabling "magic quotes" (automatic escaping) for GET/POST/COOKIE variables.

When magic_quotes_gpc is enabled in PHP's configuration, PHP uses a method identical to addslashes() to automatically insert backslashes before certain problematic characters (\, ', ", and \0) in GET/POST/COOKIE values before they are passed to the script. The intent was to reduce the chance of their causing an error when interpolated directly into HTML or SQL, enabling PHP developers to write safer code without changing their habits.

Among their numerous drawbacks, though, is that if a script does properly escape data, assuming that magic quotes will be off, it will often break when this option is enabled; the resulting data will often have visible backslashes in it. In order to work both ways, a script needs to remove the added backslashes (using stripslashes()) if, and only if, magic quotes are enabled. Most problems these days have to do either with double-escaping caused by magic quotes, or with disabling the option on servers/hosts that have this misfeature enabled and do not allow configuration changes.

Magic quotes have been deprecated as of PHP 5.3, and removed entirely as of 5.4. Even in versions that still support them, their use is not recommended. The suggested course of action is instead to escape the data as needed, using a method appropriate for the data's intended destination.

More reading:

72 questions
41
votes
13 answers

How to turn off magic quotes on shared hosting?

I want to turn off PHP's magic quotes. I don't have access to php.ini. When I tried to add php_flag magic_quotes_gpc off to my .htaccess file, I get a 500 internal server error. This is what my .htaccess file looks like: AddType x-mapp-php5…
John
  • 28,573
  • 67
  • 217
  • 373
7
votes
3 answers

Magic Quotes Off, Still Slashes

I have $_POST variables incoming in from tags that have slashes on quotes. I know that magic quotes are off, and use the if (get_magic_quotes_gpc()) statement to stripslashes in case they are. However, slashes are still getting added. Why is…
notam2774
  • 171
  • 2
  • 12
7
votes
4 answers

Work around magic quotes, or just make sure they're off?

Is it worth changing my code to be "more portable" and able to deal with the horror of magic quotes, or should I just make sure that it's always off via a .htaccess file? if (get_magic_quotes_gpc()) { $var = stripslashes($_POST['var']); } else…
nickf
  • 499,078
  • 194
  • 614
  • 709
4
votes
6 answers

Why is turning magic_quotes_gpc on considered a bad practice?

Why is turning on magic_quotes_gpc in PHP considered a bad practice?
Itay Moav -Malimovka
  • 48,785
  • 58
  • 182
  • 262
4
votes
2 answers

Which superglobals are affected by magic_quotes_gpc = 1?

By looking at the name of this directive one may think that magic_quotes are only applied to $_GET, $_POST and $_COOKIE superglobals but there is one perturbing comment on the PHP Manual: Please note, that when magic_quotes_gpc is set not only …
Alix Axel
  • 141,486
  • 84
  • 375
  • 483
3
votes
3 answers

FLOW3 requires the PHP setting "magic_quotes_gpc" set to Off. (Error #1224003190)

While configuring FLOW3 on mac, I modified the php.ini in terms of setting magic_quotes_gpc = off and on restarting server I get the magic_quotes_gpc = off by browsing http://localhost:8888/MAMP/phpinfo.php But on running: $ ./flow3…
Sidra Sultana
  • 529
  • 1
  • 5
  • 20
3
votes
4 answers

Does PHP auto escape quotes in a string which is passed by GET or POST?

Consider file a.php: a.php?a=abcd' prints abcd\'. I think PHP auto escape quotes, but I couldn't find a document about this. Is it true? Because I want to make sure - I'm quite lazy, so I didn't prevent SQL injection…
JiminP
  • 2,036
  • 19
  • 26
3
votes
1 answer

turning magic quotes off in bitnami stack

I have bitnami stack on EC2 instance, I want to turn off magic quotes, but in the php.ini I cant find the option to turn off. I have seen how to turn off magic quotes through code but if I do echo 'Value for '.get_magic_quotes_gpc(); It only echoes…
user1765876
3
votes
3 answers

json_decode() not working on the web server

I have a php script which is working perfectly on my localhost server. When I moved everything from the localhost to the web server my json_decode is not working. I have tried json_encode and still nothing. what could be a problem for such…
user123_456
  • 5,011
  • 20
  • 80
  • 136
2
votes
2 answers

When does filter_input() remove slashes of POST variables?

I created a small PHP-script, that runs on a server with PHP 5.2.17 and the magic_quotes_gpc directive enabled. I have no write-access to the php.ini file, and I'd like to remove all slashes from user inputs. This should work even if the…
R_User
  • 9,332
  • 22
  • 68
  • 115
2
votes
1 answer

Is it possible to make a portable password storing PHP code when magic_quotes_qpc is on?

I am developing my first website. My shared hosting provider has magic_quotes_qpc on and doesn't want to change it. As I understand, there is a following problem with password storing: 1. User types in a value like "strong'password" into a…
Kadilov
  • 135
  • 1
  • 6
2
votes
2 answers

Quotes being escaped when magic_quotes_gpc is set to off

Magento is escaping apostrophes when magic_quotes_gpc is set to off. When I set magic_quotes_gpc to on, Magento stops inserting slashes. It's completely backwards. I can't have Magento escaping my apostrophes, but I also do not want to have…
Nick
  • 8,822
  • 6
  • 41
  • 65
2
votes
3 answers

PHP - magic quotes gpc and stripslashes question

Okay my hosting company has magic_quotes_gpc turned ON and I coded my PHP script using stripslashes() in preparation of this. But now the hosting company says its going to turn magic_quotes_gpc OFF and I was wondering what will happen now to my data…
HELP
  • 13,143
  • 19
  • 61
  • 96
2
votes
1 answer

Fixing magic_quote affected data

I've got a CMS to fix some issues. Since the hosting service has enabled php_magic_quotes in the server their database contains content with slashes. Once I got the project I requested the hosting party to switch off the magic_quotes and the issues…
Prasad Rajapaksha
  • 5,706
  • 8
  • 34
  • 49
1
vote
4 answers

magic_quotes on php 5.3 will not go away

I have an Ubuntu 10.04 server, running PHP 5.3.2 and I have these lines set in my php.ini file: magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off There are NO other php.ini files (I searched the whole hard drive), I…
cegfault
  • 6,021
  • 3
  • 21
  • 48
1
2 3 4 5