I'm trying to add CSRF protection to my current form. I had a programmer assist me, but I feel like there is missing code. If he only did half the work than it's real unfortunate to those that may be oblivious to this.
Here is the session found in the index where the form is:
<?php
session_start();
$csrfToken= md5(uniqid());
$_SESSION['csrfToken'] = $csrfToken;
session_write_close();
?>
Here is the actual form part:
<form id="popup-form" role="form" method="post" action="intake-form.php">
<!-- This fields are taken from intake form but hidden -->
<input type="hidden" name="csrfToken" value="<?php echo $csrfToken ?>" />
Here is part of the php file that sends the form. That I am "securing" , includes/SMTP includes the mail function that sends out the form.
//Secure the Form
session_start();
$csrfToken = $_SESSION['csrfToken'];
unset($_SESSION['csrfToken']);
session_write_close();
if ($csrfToken && $_POST['csrfToken']==$csrfToken) {
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_POST['email'] ;
$name = $_POST['name'] ;
$message = $_POST['message'] ;
$phone = $_POST['phone'] ;
$additional = $_POST['additionalInfo'] ;
$fundedOption = $_POST['fundedOption'] ;
include 'includes/smtp.php';
}