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
1
vote
0 answers

ownCloud not installing due to magic quotes error

i want to install ownCloud on my server for personal use but it is giving error. "Magic Quotes is enabled. ownCloud requires that it is disabled to work properly. Magic Quotes is a deprecated and mostly useless setting that should be disabled.…
1
vote
0 answers

Why are magic quotes being applied in this scenario?

I can't post my company's proprietary code, but here is some concept code that should get the point across. It may not be free of syntax errors. Server 1: PHP 5.3.5, php.ini magic_quotes_gpc = On (default) On this server we render a page using…
Gundark
  • 431
  • 5
  • 10
1
vote
1 answer

Tried all possible ways to turn php_flag magic_quotes_gpc off during Kayako 4 setup

Tried all possible ways..Right from the php.ini to .htaccess to turn php_flag magic_quotes_gpc off during Kayako 4 setup but all resulted in failure. I have tried placing "php_flag magic_quotes_gpc off" in .htaccess file. and I placed a php.ini file…
1
vote
4 answers

PHP: magic_quotes_gpc

According to the PHP manual: Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically. But does this…
Jori
  • 1,122
  • 2
  • 18
  • 36
1
vote
1 answer

Why does this PDO DB insertion with magic_quotes_gpc off still result in backslashes in db?

On the server I'm using (running php_fastcgi5), there is an .htaccess file in the root directory containing this directive, to turn off magic_quotes_gpc: php_flag magic_quotes_gpc off A phpinfo() output reports that the local value for…
John Doe
  • 97
  • 2
  • 10
1
vote
1 answer

Should I try to rid my MySQL database of back-slashes?

I'm using PDO prepared statements to insert data into a MySQL database, and I notice that apostrophes (single quotes) in strings are being stored in the database with back-slashes (\) preceding them. I use stripslashes($string) on output, and of…
John Doe
  • 97
  • 2
  • 10
0
votes
2 answers

Cannot redeclare a function error

I am trying to remove the slashes from magic quotes from an array. So I have two functions, one is to remove the slashes, another is to set the variable. // Strip slashes from an array. function strip_magic_quotes($array) { if…
Run
  • 54,938
  • 169
  • 450
  • 748
0
votes
1 answer

Wordpress escaping quoting ONLY when inserting into the database

here's another problem: I have built a custom plugin... all works except when I update a record everything gets escaped and magic quoted. I have stripslahsed_deep the $_POST and the rest, however it seems I can see the query ACTUALLY going in by a…
johnbell
  • 7
  • 2
0
votes
1 answer

magic_quotes_gpc removed since 5.4

I'm upgrading some code to php 7+. This directive is removed in 5.4. So since 5.4, this if will ALWAYS evaluate false right? if (ini_get("magic_quotes_gpc")) { some_code; } Is this for sure for php 5.5+ right?
voskys
  • 121
  • 1
  • 9
0
votes
0 answers

Why is my form inserting backslashes before quotes?

My php code to edit a text document is adding a backslash anywhere a ' or a " is used and I can't figure out why. Anybody ever ran into this before? How did you fix it?
0
votes
3 answers

Disabling magic_quotes_gpc

I have a site, locally setup. It's application development framework is Kohana. I have an error displaying the following: Unknown Error An error was detected which prevented the loading of this page. If this problem persists, please contact the…
Michel Joanisse
  • 450
  • 1
  • 9
  • 26
0
votes
1 answer

Magic Quotes GPC joomla

I cannot install Joomla because I cannot turn Magic Quotes GPC On.I tried to write in .htaccess Magic Quotes GPC On but it doesn't work.And what can I do I have no time.Thank you! Picture
sandro
  • 1
  • 4
0
votes
1 answer

Creating a real_escape_string() method for systems with magic quotes enabled

The book I'm learning PHP from says that in order to prevent people using things like quotes to alter the query, you should use the real_escape_string function. The author then goes on to say that on some older systems, where magic quotes is…
M. Salman Khan
  • 608
  • 1
  • 6
  • 16
0
votes
1 answer

My magic_quotes_gpc is on but my script won't proceed telling me it's off

My magic_quotes_gpc is on but my script won't proceed telling me it's off. I even created a php.ini file and specifically entered magic_quotes_gpc = On I uploaded a phpinfo.php file and I in deed do not see where "magic quotes" is even…
0
votes
1 answer

PHP 5.3 magic_quotes_gpc On but not working

I've a problem with magic_quotes_gpc. I'm migrating a webserver from an XP machine to a Win2003 one. PHP code is in some cases old, and not really well developed, so I really need to have magic_quotes_gpc working. I'm pretty sure that configurations…