Hi,
I just got some nice Contact Form I would like to use on my website.
The only thing I would like to change is the verification code.
The one used in that contact form is too simple with only one question [How much is 2+3?].
I found a nice Captcha from another Contact Form and I was wondering if it is possible just to add that CAPTCHA to my actual Contact Form?
I tried but I didn't succeed.
This is my actual Contact Form PHP file:
<div class="Kforma">
<?php
$error = ''; // error message
$name = ''; // sender's name
$email = ''; // sender's email address
$subject = ''; // subject
$message = ''; // the message itself
$spamcheck = ''; // Spam check
if(isset($_POST['send']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$spamcheck = $_POST['spamcheck'];
if(trim($name) == '')
{
$error = '<div class="errormsg">Unesite Ime i Prezime</div>';
}
else if(trim($email) == '')
{
$error = '<div class="errormsg">Unesite e-mail adresu</div>';
}
else if(!isEmail($email))
{
$error = '<div class="errormsg">Netacan oblik e-mail adrese</div>';
}
if(trim($subject) == '')
{
$error = '<div class="errormsg">Unesite naslov poruke</div>';
}
else if(trim($message) == '')
{
$error = '<div class="errormsg">Unesite poruku</div>';
}
else if(trim($spamcheck) == '')
{
$error = '<div class="errormsg">3+2=?!</div>';
}
else if(trim($spamcheck) != '5')
{
$error = '<div class="errormsg">Netacno! 2 + 3 = ???</div>';
}
if($error == '')
{
if(get_magic_quotes_gpc())
{
$message = stripslashes($message);
}
$to = "forumasfc@yahoo.com";
$subject = 'Poruka sa neta : ' . $subject;
// the mail message ( add any additional information if you want )
$msg = "\r\n$message";
mail($to, $subject, $msg, "From: $name\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
?>
<div style="text-align:center;">
<h1>Hvala!</h1>
<b><?=$name;?></b>, Vasa poruka je uspjesno poslata. Uskoro bi trebali da dobijete odgovor.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) || $error != '')
{
?>
<?=$error;?>
<form method="post" name="contFrm" id="contFrm" action="">
<b>Ime i Prezime:</b><br /><input name="name" type="text" class="box" id="name" size="30" value="<?=$name;?>" /><br><br>
<b>E-mail adresa:</b> <br /><input name="email" type="text" class="box" id="email" size="30" value="<?=$email;?>" /><br><br>
<b>Naslov poruke:</b> <br /><input name="subject" type="text" class="box" id="subject" size="30" value="<?=$subject;?>" /><br><br>
<b>Poruka:</b> <br /><textarea name="message" cols="60" rows="10" id="message"><?=$message;?></textarea><br /><br><br>
<b>Koliko je:</b> <b>2 + 3=</b> <input name="spamcheck" type="text" class="box" id="spamcheck" size="4" value="<?=$spamcheck;?>" /><br /><br />
<input name="send" type="image" src="Kontakt/contact_images/submit.gif" class="button" id="send" value="Posalji poruku" />
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
</div>
I could change some details back on English but I'm sure you will know where the details are such as name.. email and etc.
And this is the CAPTCHA I got from the internet:
<?php
session_start();
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = 'monofont.ttf';
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters_on_image) {
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}
$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);
/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$image_noise_color = imagecolorallocate($image, 100, 120, 180);
/* generating the dots randomly in background */
for( $i=0; $i<($image_width*$image_height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width), mt_rand(0,$image_height), 1, 1, $image_noise_color);
}
/* generating lines randomly in background of image */
for( $i=0; $i<($image_width*$image_height)/150; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height), mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}
/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code);
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);
/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
$_SESSION['6_letters_code'] = $code;
?>
It has also a small HTML included:
<HTML>
<HEAD><title>Contact Form</title></HEAD>
<BODY>
<form method="POST" name="contact_form" action="result.php">
Enter Name: <input type="text" name="name"><br>
Enter Message: <textarea name="message"></textarea><br>
<img src="captcha_code_file.php" /><br>
Enter captcha Code Here :<input id="6_letters_code" name="6_letters_code" type="text" ><br>
<input type="submit" value="Submit"><br>
</form>
</BODY>
</HTML>
And some small PHP too:
<?php
session_start();
if( $_SESSION['6_letters_code'] == $_POST['6_letters_code'] && !empty($_SESSION['6_letters_code'] ) ) {
echo 'You entered the correct code. Your message is successfully emailed.';
} else {
echo "Sorry, you have provided an invalid security code. Please <a href='contact_form_with_captcha.html'>CLICK HERE</a> to try again.";
}
?>
So I was wondering if you can tell me how to 'merge' this CAPTCHA to my actual contact form. So I want to have the same Contact Form but with this new CAPTCHA instead of having only one security question that can be easily be discovered by a single script and I would like to avoid spamming from bots.
Thanks a lot,
Fidel