PDA

View Full Version : Problem validating captcha feature..


gigiloumill
08-10-2009, 01:42 PM
Good morning:

I have a litle problem going on 22 hrs already. I set up a form with the "captcha" feature which displays the image fine. The problem is I can't get the code to validate image or send back as an error. Would someone please advise on what it is I'm doing wrong or missing. Thanks

Here's the code:

<?php session_start(); ?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body><?php


//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'me@gmail.com';

// Where to redirect after form is processed.
$url = '';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')

{
if ($value == '')
{echo "$key is empty";die;}
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';

$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking

// or you can do something really basic like this
die('The code you entered was incorrect. Go back and try again.');
}

}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>


</body>
</html>

gigiloumill
08-10-2009, 10:57 PM
O.K. it's working, however, upon form sending, the script is not redirecting form. Any help will be appreciated. Thanks

Here's the code:
<?php session_start(); ?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Where to redirect after form is processed.
$url = 'contactus.php';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------

$to = "me@gmail.com";
$subject = "Email from website";
$message = $_REQUEST["body"];
$subject = $_REQUEST["subject"];
$email = $_REQUEST["email"];

function is_valid_email($email) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}
include_once $_SERVER['DOCUMENT_ROOT'] . '/websites/c4s2/securimage/securimage.php';

$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking

// or you can do something really basic like this
die('Oops. The code you entered was incorrect. Go back and try again.');
}

if (!is_valid_email($email)) {
echo 'Sorry, invalid email';
exit;
}

$headers = "From: $email";
mail($to, $subject, $message, $headers);
echo "Thanks for submitting.";

?>
</body>
</html>

edbr
08-11-2009, 01:50 AM
there is no redirect in the script