No, no, no, no, no, no .
Use the correct function for the correct job.
addslashes
not an escape function for any context, it just adds slashes.
If you are printing in HTML, use htmlentities
(or htmlspecialchars
, if applicable).
If you are printing in JavaScript, use json_encode
.
If you are building a MySQL query, use mysql_real_escape_string
and etc.
Opponents for abuse when using addslashes
instead of json_encode
is, for example, the line: "</script><iframe src=hxxp://phising.mywebsite.com>"
This will end the script and insert the iframe from an untrusted and potentially dangerous domain.
source share