Magic quotes
Magic quotes was a feature of the PHP scripting language, wherein strings are automatically escaped—special characters are prefixed with a backslash—before being passed on.[src] It was introduced to help newcomers write functioning SQL commands without requiring manual escaping.[src] It was later described as intended to prevent inexperienced developers from writing code that was vulnerable to SQL injection attacks.[src] This feature was officially deprecated as of PHP 5.3.0 and removed in PHP 5.4, due to security concerns.[src]
Magic quotes was a feature of the PHP scripting language, wherein strings are automatically escaped—special characters are prefixed with a backslash—before being passed on.[src] It was introduced to help newcomers write functioning SQL commands without requiring manual escaping.[src] It was later described as intended to prevent inexperienced developers from writing code that was vulnerable to SQL injection attacks.[src] This feature was officially deprecated as of PHP 5.3.0 and removed in PHP 5.4, due to security concerns.[src] == Criticism == Magic quotes were enabled by default in new installations of PHP 3 and 4, but could be disabled through the magic_quotes_gpc configuration directive.[src] Since the operation of magic quotes was behind the scenes and not immediately obvious, developers may have been unaware of their existence and the potential problems that they could introduce.[src] The PHP documentation pointed out several pitfalls and recommended that, despite being enabled by default, they should be disabled.[src] Problems with magic quotes included: Not all user supplied data is intended for insertion into a database.[src] It may be rendered directly to the screen, stored in a session, or previewed before saving.[src] This can result in backslashes being added where they are not wanted and being shown to the end user.[src] This bug often creeped into even widely used software.[src] Not all user supplied data used in database queries is obtained directly from sources protected by magic quotes.[src] For instance, a user-supplied value might be inserted into a database, protected by magic quotes, and later retrieved from the database and used in a subsequent database operation.[src] The latter use is not protected by magic quotes, and a naive programmer used to relying on them may be unaware of the need to protect it explicitly.[src] Whatever protection magic quotes offer, they only work for quoted strings, leaving other query parts (such as numbers or column names) entirely unprotected, and giving the developer a false feeling of security.[src] Magic quotes also use the generic functionality provided by PHP's addslashes() function, which is not Unicode-aware and is still subject to SQL injection vulnerabilities in some multi-byte character encodings.[src] Database-specific functions such as mysql_real_escape_string() or, where possible, prepared queries with bound parameters, are preferred.[src] While many database management systems support escaping quotes with a backslash, the standard actually calls for using another quote.[src] Thus, magic quotes can only offer protection for databases configured to support escaping quotes with a backslash.[src] Code written assuming magic quotes are disabled will not work in an environment where they are enabled or vice versa.[src] This can be worked around using the ini_get() or ini_set() functions but requires forethought by programmers , and usage of ini_set() is generally seen as bad practice .[src] Adding magic quotes and subsequently removing them where appropriate incurs a small but unnecessary amount of performance overhead.[src] Magic quotes do not protect against other common, related, security vulnerabilities such as Cross-site scripting (XSS) or SMTP header injection attacks, that a beginner might assume are prevented by magic quotes.[src] In November 2005, the core PHP developers decided that because of these problems, the magic quotes feature would be removed from PHP 6.[src] When development of PHP 6 stalled and development continued on the 5.x branch instead, the feature was deprecated in PHP 5.3.0 and removed in 5.4.[src]
29 sentences · 29 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Magic quotes." encyclopegia.org, 2026, https://encyclopegia.org/wiki/magic-quotes. Accessed 28 November 2026.
Chicago
"Magic quotes." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/magic-quotes.
APA
encyclopegia.org. (2026). Magic quotes. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/magic-quotes
Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON