Ist das Verhindern von XSS und SQL Injection so einfach wie dies

Frage: VerhindertXSS (Cross-Site-Scripting) so einfach wie möglichstrip_tags auf alle gespeicherten Eingabefelder und läufthtmlspecialchars auf jedem angezeigten Ausgang ... und zu verhindernSQL-Injektion mit PHP PDO vorbereiteten Anweisungen?

Hier ist ein Beispiel:

// INPUT: Input a persons favorite color and save to database
// this should prevent SQL injection ( by using prepared statement)
// and help prevent XSS  (by using strip_tags)
$sql = 'INSERT INTO TABLE favorite (person_name, color) VALUES (?,?)';
$sth = $conn->prepare($sql);
$sth->execute(array(strip_tags($_POST['person_name']), strip_tags($_POST['color'])));


// OUTPUT: Output a persons favorite color from the database
// this should prevent XSS (by using htmlspecialchars) when displaying
$sql = 'SELECT color FROM favorite WHERE person_name = ?';
$sth = $conn->prepare($sql);
$sth->execute(array(strip_tags($_POST['person_name'])));
$sth->setFetchMode(PDO::FETCH_BOTH);
while($color = $sth->fetch()){
  echo htmlspecialchars($color, ENT_QUOTES, 'UTF-8');
}

Antworten auf die Frage(6)

Ihre Antwort auf die Frage