Updated filtering to modernize it a bit

This commit is contained in:
Paul 2023-05-10 23:20:48 -05:00
parent c02727e444
commit 56c808c984
2 changed files with 7 additions and 11 deletions

0
README.md Normal file → Executable file
View file

18
contactform.php Normal file → Executable file
View file

@ -13,6 +13,9 @@ class antibot {
function __constructor(){ function __constructor(){
$passfail = 0; $passfail = 0;
// beter way to filter input data
$_POST = filter_var_array($_POST, FILTER_UNSAFE_RAW);
$_GET = filter_var_array($_GET, FILTER_UNSAFE_RAW);
} }
private function fromtest() { private function fromtest() {
@ -49,19 +52,12 @@ class antibot {
return $passfail; return $passfail;
} }
private function test_input($data) { // Cleans the input
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
private function sndmsg($target) { private function sndmsg($target) {
// First clean the data // First clean the data
$fname = $this->test_input($_POST["fname"]); $fname = $_POST["fname"];
$lname = $this->test_input($_POST["lname"]); $lname = $_POST["lname"];
$email = $this->test_input($_POST["email"]); $email = $_POST["email"];
$comments = $this->test_input($_POST["comments"]); $comments = $_POST["comments"];
// compile cleaned message // compile cleaned message
$msg = "From $fname Subject $lname email $email with message $comments"; $msg = "From $fname Subject $lname email $email with message $comments";
mail($target,"Website Form Submission",$msg); mail($target,"Website Form Submission",$msg);