<?php
session_start
();

//set the session if visitor types in required text field.
if (!isset($_GET['confirm'])) $_SESSION['confirm_real_sig'] = md5(time());
if (
$_GET['confirm']==$_SESSION['confirm_real_sig']) $_SESSION['confirm_real'] = time();
//

//if real person
if ($_POST && isset($_SESSION['confirm_real'])) {

    
//do whatever else needs to be done (insert into database, send email, etc.)

    
echo "Your message was sent successfully.";
    
//header('Location: success.php'); 
    
unset($_SESSION['confirm_real']); die;

}

//if automated spammer
if ($_POST && !isset($_SESSION['confirm_real'])) {

    echo 
"Error: Your message was not sent."; die;

}
//

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SPAM Protection Using PHP and jQuery</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script src="jquery-1.3.2.min.js" type="text/javascript"></script>

<script>

$(function() {  

//
    $(".required").blur(function() {  

        $.get("form.php", { //name of the PHP file containing the session code
            confirm: '<?php echo $_SESSION['confirm_real_sig']; ?>'
        },

        function(data){
            //alert("Data Loaded: " + data);
        });

    });
});
//

</script>

</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <h1>SPAM Protection Using PHP and jQuery</h1>
  Name<br />
  <input name="name" type="text" id="name" class="required" />
  <br />
  <br />
Email<br />
<input name="email" type="text" id="email" size="35" />
<br />
<br />
Comments<br />
<textarea name="comments" cols="65" rows="5" id="comments"></textarea>
<br />
<br />
<input type="submit" name="Submit" value="Submit" />
<br />

</form>
</body>
</html>