Good day friends, please i am still an upcoming developer please could you help me check if this contact form code is secured from hackers. Thanks
<?php
require “define.php”;
$seotitlemeta = “Contact $sitename”;
include ‘./themes/header.php’;
function filter_spam(&$string){ $url = str_replace(array("’", ‘’, ‘%20’), ’ ‘, $string); $url = preg_replace(’~[\pL0-9]+u’, ’ ', $url); $url= strtolower($url); $url = trim($url, “”); return $url;}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
$data = strip_tags($data);
return $data; } ?>
Contact <?php echo $sitename;?>
<?php if ($SERVER["REQUEST_METHOD"] == "POST") { $code1= trim(preg_replace(array("'", "[^a-z0-9]+"), array("", ""), strtolower(test_input($POST['code']))), "-"); $code1 = substr($code1, 0, 10); $code= trim(preg_replace(array("'", "[^0-9]+"), array("", ""), strtolower(bin2hex(test_input($POST['code1'])))), "-"); $code = substr($code, 0, 10); if (filter_var(test_input($POST['mail']), FILTER_VALIDATE_EMAIL)) { if(strlen(test_input($POST["message"])) > 5){ $email_sumbit = test_input($POST['mail']); $contact_name = test_input(filter_spam($POST['name'])); $subject_submit = test_input($POST['head']); $message_submit= test_input($POST["message"]); if($code1!== $code) { } else { $from = "$email_sumbit"; $to_email = "[email protected]"; $subject = $subject_submit; $message = $message_submit; $headers = "From: $contact_name $from"; mail($to_email,$subject,$message,$headers); $sent_show_response = ''; }}}} ?>
<?php echo $sent_show_response; ?>
<?php if ($message_sent_remove_form == '1'){ } else{ ?><?php $Random_code=mt_rand(); $Random_code = substr($Random_code, 0, 5); $Random_codehex = substr(bin2hex($Random_code), 0, 10); ?>