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
1 answer

Should I always use stripslashes for _POST _GET and _COOKIE variables

I'm really confused when I read about the function get_magic_quotes_gpc() in PHP. Everywhere it's said that the function is deprecated (example). But what is the default behaviour in PHP 5.3? I used to check, if magic_quotes_gpc in on and stripped…
R_User
  • 10,682
  • 25
  • 79
  • 120
1
vote
1 answer

Are magic quotes vulnerable to Sql Injection ? Should i use stripslashes and then sanitize the input?

I'm confused about these magic quotes. They are enabled on my server, and my question is should i disable them by using functions like : if(get_magic_quotes_gpc()){ $username=stripslashes($username); $password=stripslashes($password); } to…
aygeta
  • 429
  • 3
  • 7
  • 17
1
vote
2 answers

get_magic_quotes_gpc going away, how to bulk update the code

I have thousands of instances of calls to get_magic_quotes_gpc. Since get_magic_quotes_gpc is going away, I found a recommendation to simply replace call with "false". Then the code: if (get_magic_quotes_gpc()) { $cell =…
1
vote
2 answers

How to remove magic quotes if php.ini/.htaccess are not editable?

For some reason, all my quotes are being escaped and displayed as \". Previously, it was okay. Then I looked at phpinfo() and saw that my magic_quotes_gpc is turned on. However, I cannot find the directory /usr/local/lib/ where php.ini file is and I…
catandmouse
  • 11,309
  • 23
  • 92
  • 150
1
vote
4 answers

Can "magic_quotes_gpc" be enabled in PHP 5.3?

In PHP 5.3, can "magic_quotes_gpc" be enabled? I understand that it is deprecated in PHP 5.3, but a PHP script I am installing requires this otherwise it won't work.
Michael
  • 13
  • 1
  • 3
1
vote
3 answers

Best method of disabling php magic quotes without php.ini or .htaccess

I am needing to write portable code that will run on a shared server with magic_qoutes_gpc enabled and I am unable to change that in php.ini or .htaccess. (the server is running php 5.2) It seems there are numerous functions to stripslaches from all…
angrydust
  • 453
  • 3
  • 14
1
vote
2 answers

Zend Framework double escaping

I use Zend framework with doctrine for a project , the problem is that when i insert in database a string like O'Shea it inserts O\'Shea. I guess this is because of double escaping. One when i get the post and one when i use doctrine, why when i…
Centurion
  • 5,169
  • 6
  • 28
  • 47
1
vote
2 answers

Form wont return array when using this function to overcome magic quotes?

To counteract magic quotes I have this function set at the top of every page. However it seems to be affecting when I have an array in a form . if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ),…
Stefan P
  • 1,013
  • 2
  • 18
  • 34
1
vote
2 answers

Using get_magic_quotes_gpc on PHP Version 5.2.14 or equivalent for PHP Version 6

Our site is using PHP Version 5.2.14 Lately our hoster probably changed magic-quote defenition, and I came up with the suggested solution [code bellow] Is this solution OK for PHP Version 5.2.14 ? What should I change when we upgrade to PHP version…
Atara
  • 3,523
  • 6
  • 37
  • 56
1
vote
3 answers

Testing with varying system ini settings

Ok, so here's the issue I've run into. On some of our production systems, we have magic quotes gpc enabled. There's nothing I can do about that. So, I've built my request data handing classes to compensate: protected static function…
ircmaxell
  • 163,128
  • 34
  • 264
  • 314
1
vote
2 answers

Notice: Undefined variable: magic_quotes_active in C:\wamp\www

I'm very new to php and this m first project but am stuck which this kind of error: Notice: Undefined variable: magic_quotes_active in C:\wamp\www\mysite\includes\functions.php on line 16 HERE are my codes; function mysqli_prep($value) { …
malma
  • 19
  • 2
1
vote
1 answer

Get unescaped POST, not magic quoted values in WordPress

Following the question: With "magic quotes" disabled, why does PHP/WordPress continue to auto-escape my POST data? In WordPress, all superglobals are escaped even if magic quotes are off. So, following this answer: With "magic quotes" disabled, why…
yeahman
  • 2,737
  • 4
  • 21
  • 25
1
vote
2 answers

PHP adds escape back slashes. How to stop this

Background: I am not a php programmer, and I only know enough to get the web service parts of my iOS apps working. I am finding that my php is adding backslashes to my text, when I don't want it to. For example if I set up some variables like…
narco
  • 830
  • 8
  • 21
1
vote
2 answers

Linux magic quotes still on even though disabled in php5 fpm .ini file

So I installed nginx not too long ago, and I can't figure out how to turn off magic_quotes_gpc. In the php5-fpm php.ini it has the following lines: magic_quotes_gpc = Off ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(),…
Gavin Sellers
  • 654
  • 1
  • 15
  • 27
1
vote
5 answers

Antidote for magic_quotes_gpc()?

I've seen dozens of PHP snippets that go like this: function DB_Quote($string) { if (get_magic_quotes_gpc() == true) { $string = stripslashes($string); } return mysql_real_escape_string($string); } What happens if I call…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500