<s>
Magic	B-Language
quotes	I-Language
was	O
a	O
feature	O
of	O
the	O
PHP	B-Application
scripting	B-Language
language	I-Language
,	O
wherein	O
strings	O
are	O
automatically	O
escapedspecial	O
characters	O
are	O
prefixed	O
with	O
a	O
backslashbefore	O
being	O
passed	O
on	O
.	O
</s>
<s>
It	O
was	O
later	O
described	O
as	O
intended	O
to	O
prevent	O
inexperienced	O
developers	O
from	O
writing	O
code	O
that	O
was	O
vulnerable	O
to	O
SQL	B-Language
injection	I-Language
attacks	I-Language
.	O
</s>
<s>
This	O
feature	O
was	O
officially	O
deprecated	O
as	O
of	O
PHP	B-Application
5.3.0	O
and	O
removed	O
in	O
PHP	B-Application
5.4	O
,	O
due	O
to	O
security	O
concerns	O
.	O
</s>
<s>
The	O
current	O
revision	O
of	O
the	O
PHP	B-Application
manual	O
mentions	O
that	O
the	O
rationale	O
behind	O
magic	B-Language
quotes	I-Language
was	O
to	O
"	O
help	O
 [ prevent ] 	O
code	O
written	O
by	O
beginners	O
from	O
being	O
dangerous.	O
"	O
</s>
<s>
It	O
was	O
however	O
originally	O
introduced	O
in	O
PHP	B-Application
2	O
as	O
a	O
php.h	O
compile-time	O
setting	O
for	O
msql	O
,	O
only	O
escaping	O
single	O
quotes	O
,	O
"	O
making	O
it	O
easier	O
to	O
pass	O
form	O
data	O
directly	O
to	O
msql	O
queries	O
"	O
.	O
</s>
<s>
The	O
use	O
scope	O
for	O
magic	B-Language
quotes	I-Language
was	O
expanded	O
in	O
PHP	B-Application
3	O
.	O
</s>
<s>
(	O
This	O
was	O
most	O
accurate	O
when	O
PHP	B-Application
2	O
and	O
PHP	B-Application
3	O
were	O
current	O
,	O
since	O
the	O
primary	O
supported	O
databases	B-Application
allowed	O
only	O
1-byte	O
character	O
sets	O
.	O
)	O
</s>
<s>
Magic	B-Language
quotes	I-Language
were	O
enabled	O
by	O
default	O
in	O
new	O
installations	O
of	O
PHP	B-Application
3	O
and	O
4	O
,	O
but	O
could	O
be	O
disabled	O
through	O
the	O
magic_quotes_gpc	O
configuration	O
directive	O
.	O
</s>
<s>
Since	O
the	O
operation	O
of	O
magic	B-Language
quotes	I-Language
was	O
behind	O
the	O
scenes	O
and	O
not	O
immediately	O
obvious	O
,	O
developers	O
may	O
have	O
been	O
unaware	O
of	O
their	O
existence	O
and	O
the	O
potential	O
problems	O
that	O
they	O
could	O
introduce	O
.	O
</s>
<s>
The	O
PHP	B-Application
documentation	O
pointed	O
out	O
several	O
pitfalls	O
and	O
recommended	O
that	O
,	O
despite	O
being	O
enabled	O
by	O
default	O
,	O
they	O
should	O
be	O
disabled	O
.	O
</s>
<s>
Problems	O
with	O
magic	B-Language
quotes	I-Language
included	O
:	O
</s>
<s>
Not	O
all	O
data	O
that	O
are	O
supplied	O
by	O
the	O
user	O
and	O
used	O
in	O
a	O
database	B-Application
query	I-Application
are	O
obtained	O
directly	O
from	O
sources	O
protected	O
by	O
magic	B-Language
quotes	I-Language
.	O
</s>
<s>
For	O
instance	O
,	O
a	O
user-supplied	O
value	O
might	O
be	O
inserted	O
into	O
a	O
database	O
,	O
protected	O
by	O
magic	B-Language
quotes	I-Language
,	O
and	O
later	O
retrieved	O
from	O
the	O
database	O
and	O
used	O
in	O
a	O
subsequent	O
database	O
operation	O
.	O
</s>
<s>
The	O
latter	O
use	O
is	O
not	O
protected	O
by	O
magic	B-Language
quotes	I-Language
,	O
and	O
a	O
naive	O
programmer	O
used	O
to	O
relying	O
on	O
them	O
may	O
be	O
unaware	O
of	O
the	O
need	O
to	O
protect	O
it	O
explicitly	O
.	O
</s>
<s>
Magic	B-Language
quotes	I-Language
also	O
use	O
the	O
generic	O
functionality	O
provided	O
by	O
PHP	B-Application
's	O
addslashes( )	O
function	O
,	O
which	O
is	O
not	O
Unicode-aware	O
and	O
is	O
still	O
subject	O
to	O
SQL	B-Language
injection	I-Language
vulnerabilities	O
in	O
some	O
multi-byte	O
character	O
encodings	O
.	O
</s>
<s>
Database-specific	O
functions	O
such	O
as	O
mysql_real_escape_string( )	O
or	O
,	O
where	O
possible	O
,	O
prepared	B-Language
queries	I-Language
with	O
bound	O
parameters	O
,	O
are	O
preferred	O
.	O
</s>
<s>
While	O
many	O
database	B-Application
management	I-Application
systems	I-Application
support	O
escaping	O
quotes	O
with	O
a	O
backslash	O
,	O
the	O
standard	O
actually	O
calls	O
for	O
using	O
another	O
quote	O
.	O
</s>
<s>
Magic	B-Language
quotes	I-Language
offer	O
no	O
protection	O
for	O
databases	B-Application
not	O
set	O
up	O
to	O
support	O
escaping	O
quotes	O
with	O
a	O
backslash	O
.	O
</s>
<s>
Portability	O
is	O
an	O
issue	O
if	O
an	O
application	O
is	O
coded	O
with	O
the	O
assumption	O
that	O
magic	B-Language
quotes	I-Language
are	O
enabled	O
and	O
is	O
then	O
moved	O
to	O
a	O
server	O
where	O
they	O
are	O
disabled	O
,	O
or	O
vice	O
versa	O
.	O
</s>
<s>
Adding	O
magic	B-Language
quotes	I-Language
and	O
subsequently	O
removing	O
them	O
where	O
appropriate	O
incurs	O
a	O
small	O
but	O
unnecessary	O
amount	O
of	O
performance	O
overhead	O
.	O
</s>
<s>
Magic	B-Language
quotes	I-Language
do	O
not	O
protect	O
against	O
other	O
common	O
security	O
vulnerabilities	O
such	O
as	O
cross-site	O
scripting	O
attacks	O
or	O
SMTP	B-Protocol
header	I-Protocol
injection	I-Protocol
attacks	O
.	O
</s>
<s>
In	O
November	O
2005	O
the	O
core	O
PHP	B-Application
developers	O
decided	O
that	O
because	O
of	O
these	O
problems	O
,	O
the	O
magic	B-Language
quotes	I-Language
feature	O
would	O
be	O
removed	O
from	O
PHP	B-Application
6	O
.	O
</s>
<s>
When	O
development	O
of	O
PHP	B-Application
6	O
stalled	O
and	O
development	O
continued	O
on	O
the	O
5.x	O
branch	O
instead	O
,	O
the	O
feature	O
was	O
deprecated	O
in	O
PHP	B-Application
5.3.0	O
and	O
removed	O
in	O
5.4	O
.	O
</s>
<s>
Some	O
languages	O
such	O
as	O
Perl	B-Language
and	O
Ruby	B-Language
opt	O
for	O
an	O
approach	O
involving	O
data	O
tainting	O
,	O
where	O
data	O
from	O
untrusted	O
sources	O
,	O
such	O
as	O
user	O
input	O
,	O
are	O
considered	O
"	O
tainted	O
"	O
and	O
can	O
not	O
be	O
used	O
for	O
dangerous	O
operations	O
until	O
explicitly	O
marked	O
as	O
trustworthy	O
,	O
usually	O
after	O
validation	O
or	O
encoding	O
.	O
</s>
<s>
Modern	O
database	O
engines	O
and	O
libraries	O
use	O
parameterised	B-Language
queries	I-Language
to	O
pass	O
data	O
to	O
the	O
database	O
separately	O
from	O
SQL	O
commands	O
,	O
greatly	O
reducing	O
the	O
need	O
to	O
escape	O
data	O
before	O
constructing	O
the	O
queries	O
.	O
</s>
