My contact page doesn’t work when I put the math security number to be checked. This is the live contact page http://aproapetot.ro/contact.php
and this is the php contact page with the math security. Please, someone tell me where I made a mistake.
<script language="javascript" type="text/javascript">
// this is just a simple reload; you can safely remove it; remember to remove it from the image too
function reloadCaptcha()
{
document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
}
</script>
<?php
if (isset($_POST['contact'])) { // Handle the form.
// Need the database connection:
//require ('includes/mysql.inc.php');
// Trim all the incoming data:
$trimmed = array_map('trim', $_POST);
// Assume invalid values:
$fn = $ln = $email = $mesaj = $secure = FALSE;
// Check for a first name:
if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) {
$fn = $trimmed['first_name'];
} else {
echo '<p class="error">Va rugam sa introduceti prenumele !</p>';
}
// Check for a last name:
if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) {
$ln = $trimmed['last_name'];
} else {
echo '<p class="error">Va rugam sa introduceti nummele !</p>';
}
// Check for an email address:
if (filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) {
$email = $trimmed['email'];
} else {
echo '<p class="error">Adresa de email nu este valida !</p>';
}
// Check for a message:
if (isset($_POST['mesaj'] )) {
$mesaj = $_POST['mesaj'];
} else {
echo '<p class="error">Va rugam sa introduceti mesajul !</p>';
}
// Check for a security number:
if((isset($_POST['secure'])) == $_SESSION['security_number']){
$secure = $_POST['secure'];
} else {
echo '<p class="error">Va rugam verificati codul de validare!</p>';
}
if($fn && $ln && $email && $mesaj && $secure) { // If everything's OK...
// Create the body:
$body = " DATE PERSONALE \n\n
Nume: $ln \n
Prenume: $fn \n
Email: $email \n\n
MESAJ \n $mesaj \n ";
// Make it no longer than 70 characters long:
$body = wordwrap($body, 100);
// Send the email:
mail('@yahoo.com', 'Contact Form Submission', $body, "From:$email");
// Print a message:
echo '<p><em>Va multumim ca ne-ati contactat. O sa va raspundem cat mai repede posibil.</em></p>';
} else { // If one of the data tests failed.
echo '<p class="error">Va rugam sa incercati din nou.</p>';
}
} // End of the main Submit conditional.
?>
<form action="contact.php" method="post" class="basic-grey">
<h1>Pagina de Contact</h1>
<label>
<span>Prenumele:</span>
<input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" />
</label>
<label>
<span>Numele:</span>
<input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" />
</label>
<label>
<span>Email:</span>
<input type="text" name="email" size="30" maxlength="60" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" />
</label>
<label>
<span>Mesaj:</span>
<textarea name="mesaj" value="<?php if (isset($_POST['mesaj'])) echo $_POST['mesaj']; ?>" /></textarea>
</label>
<label>
<span class="explain">click pe imagine pentru reincarcare</span>
<img src="library/image.php" alt="Click to reload image" title="Click to reload image" id="captcha" onclick="javascript:reloadCaptcha()" />
</label>
<label>
<span>Scrieti rezultatul</span>
<input type="text" class="contact_math" name="secure" value="<?php if (isset($__POST['secure'])) echo $_POST['secure']; ?>" onclick="this.value=''" />
</label>
<label>
<span> </span>
<input type="submit" name="contact" class="button" value="Trimite" />
</label>
</form>