我一直试图阅读很多关于尝试获取安全的html表单给我发电子邮件的内容。我创建了一个表单,但我很好奇它的安全性。我还没有添加电子邮件控件。
由于它会在网站上出现,我对任何注射都感到害怕。到目前为止我所做的是使用htmlentities()保护动作,使用w3学校的test_input函数并使用require函数,但我知道可以很容易地取出。
提前致谢!
<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["telnr"]);
$comment = test_input($_POST["message"]);
echo"Bedankt voor het invullen, we nemen zo snel mogelijk contact met u op.";
}
else{
?>
<form action="<?php echo htmlentities($_SERVER["PHP_SELF"]);?>" method="post">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">naam</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" placeholder="naam" required>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">e-mail</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="email" placeholder="e-mail" required>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">tel.nr</label>
<div class="col-sm-10">
<input type="tel" class="form-control" name="telnr" placeholder="telefoonnummer" required>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">bericht</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="message" placeholder="bericht" required>
</div>
</div>
<div class="form-group row text-center">
<div class="offset-sm-2 col-sm-10">
<button type="submit" class="btn btn-primary">Verstuur bericht!</button>
</div>
</div>
</form>
<?php } ?>