J'ai ce script qui recueille des données des utilisateurs et je veux vérifier leurs données pour le code malveillant (tels que les injections XSS et SQL) en utilisant HTML Purifier, mais comment l'ajouter à mon script de soumission de formulaire PHP?Comment intégrer HTML Purifier pour filtrer les données soumises par les utilisateurs?
Voici mon code HTML Purifier:
require_once '../../htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
Voici mon code de soumission de formulaire PHP:
if (isset($_POST['submitted'])) { // Handle the form.
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*, profile.*
FROM users
INNER JOIN contact_info ON contact_info.user_id = users.user_id
WHERE users.user_id=3");
$about_me = mysqli_real_escape_string($mysqli, $_POST['about_me']);
$interests = mysqli_real_escape_string($mysqli, $_POST['interests']);
if (mysqli_num_rows($dbc) == 0) {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"INSERT INTO profile (user_id, about_me, interests)
VALUES ('$user_id', '$about_me', '$interests')");
}
if ($dbc == TRUE) {
$dbc = mysqli_query($mysqli,"UPDATE profile
SET about_me = '$about_me', interests = '$interests'
WHERE user_id = '$user_id'");
echo '<p class="changes-saved">Your changes have been saved!</p>';
}
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error($mysqli);
return;
}
}