:
- SQL-,
mysql_real_escape_string
SQL- , . - XSS / HTML, HTML , HTML.
- JSON JSON, CSV CSV ..
. "test"
( , ), $foo = ""test""
. , , : $foo = "\"test\""
.
SQL-, XSS HTML- - .
, , , :
$comment = "\"foo\""; // comment is "foo", including quotes
$query = 'INSERT INTO `db` (`comment`) VALUES ("' . $comment . '")';
// INSERT INTO `db` (`comment`) VALUES (""foo"")
, - SQL-. mysql_real_escape_string
:
$query = 'INSERT INTO `db` (`comment`) VALUES ("' . mysql_real_escape_string($comment) . '")';
// INSERT INTO `db` (`comment`) VALUES ("\"foo\"")
HTML escaping is exactly the same, only with various syntax issues.
You only need to avoid your values in the right context using the right method. To avoid HTML values, use htmlentities
. Do it at the right time. Avoid premature or excessive values of your values, use only the appropriate evacuation function in the right context at the right time.
source
share