htmlentities ou htmlspecialchar inopérents
Bonjour à tous
Je veux tester "htmlentities" pour pouvoir protéger ma base de donnée de malveillant qui introduirait des balises dans mon formulaire.
j'ai recopié quelques codes mais le résultat est apparemment que "htmlentities" comme "htmlspecialchars" sont inopérants
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
<?php
header('content-type: text/html; charset=utf-8');
if (isset($_POST['nom'])){
//dans l'input j'ai inscrit la phrase suivante: Un \'apostrophe\' en <strong>gras</strong>
echo "nom = ".$_POST["nom"];echo'<br/>';//affichage : nom = Un \'apostrophe\' en gras
echo "nom_htmlentities = ".(htmlentities($_POST["nom"]));echo'<br/>';//affichage : nom_htmlentities = Un \'apostrophe\' en <strong>gras</strong>
echo'<br/>';
}
$str ='Un \'apostrophe\' en <strong>gras</strong>';
echo "variable str = ". $str;echo'<br/>'; //affichage : variable str = Un 'apostrophe' en gras
echo "str_htmlentities ".(htmlentities($str,ENT_QUOTES,"UTF-8"));echo'<br/>';//affichage :str_htmlentities = Un 'apostrophe' en <strong>gras</strong>
echo'<br/>';echo'<br/>';
?>
<form action='test_reg.php' method='post'>
<input type ='text' size=10 style="width:300px;" name= "nom" >
<input type='submit' value='valider'><br><br> |