Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CAPTCHA challenge error 1

Status
Not open for further replies.

Newb2IT

IS-IT--Management
Oct 6, 2008
205
US
Hi guys I am trying to implement and CAPTCHA response on one of my forms on my website..I got instructions from here:


I have configured both client and server files per instructions but I think there is something wrong wit the server file....if i upload the client file to my website and, then go to that page, it loads fine with no problems but of course it doesn't work because i have not uploaded the sever file yet...problem happens when I upload the server file...as soon as i update the server file and i then go to the CLIENT file it does not load at all...i get an error message instead that says: The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)....i thinks this is because some of the code on my server file is not correct...can you please take a look and let me know if you see why I am having this problem?? attaches is the serve file code...this is driving me nuts..thanks! beow is my server file code:

<?php
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else
{
date_default_timezone_set( 'America/New_York' );

/*
Simple web form mailer
*/

//safe error-free retrival of post values
//required - do not touch or move
function pval($key){ return ( isset( $_POST[$key] ) ) ? $_POST[$key] : "" ; }


/***************************************************************
* Config Settings
***************************************************************/

//INFO FOR EMAIL
$to = 'sales@sxxxx.com';
$from = 'sales@xxxxxxxx.com';
$email_subject = 'New eLines Request Form';

//INFO FOR EMAIL TO Customer
$confirm_from = 'sales@xxxxxxxxx.com';
$confirm_email_subject = 'Thank you for submitting your eLines quote with xxx';

//Email Server Info
//disable the testing info on the production server

$smtp_server = 'mailwash27.xxxxxx.com';
$smtp_port = 225;
$smtp_username = 'ecommerce@xxxxxxxxxxx.com';
$smtp_password = 'xxxxxxxxxx';

//our list of required fields
//
// the form element 'key' or 'name' is on the left
//
// The printable title of the field is on the right
// this is used for the 'Please correct the following errors'
//
$required_fields = array(
'first_name' => "First Name",
'last_name' => "Last Name",
'company' => "Company",
'phone' => "Phone Number",
'email' => "Email Address",
'part_number' => "Part Number",
'ship_time' => "Shipping Time",
'ship_method' => "Shipping Method",
'hear_about_us' => "How did you hear about us?"
);
$required_file_fields = array(
'image' => 'Drawing Attachment'
);

//FORM VALUES
//for EVERY field you MUST have one of these. Not just required fields
// not just required fields. These are used to fill in the Email template
// and the thank you page. Also suitable for re-displaying the form
$first_name = pval('first_name');
$last_name = pval('last_name');
$company = pval('company');
$phone = pval('phone');
$email = pval('email');
$part_number = pval('part_number');
$ship_time = pval('ship_time');
$ship_method = pval('ship_method');
$requirements = pval('requirements');
$hear_about_us =pval('hear_about_us');


$thankyou = "thankyou.php";

$form = 'index.php';


$message = 'message.php';

$confirm_message = 'confirm_message.php';



$failure_notice = "There was an unknown error submitting your form. Please Call Us.";



$form_errors = array();
}

?>
 
are you perhaps testing this locally on an address where the $_SERVER['REMOTE_ADDRESS'] is not providing useful information?
 
I am not testing it locally...i tested it right on the live website...do i need to replace 'REMOTE_ADDRESS' with an actual server name?
 
no. you should not do that.

please post the form script.
 
form script is here...thanks a lot:

<?php

/*
* This will add the form to email support
*/
require_once 'mailer/form_settings.php';

//Any of the forms values can be used here. use the following format
/* <?php echo $first_name;?> */
//
// where $first_name is the name of the field from form_settings.php in the 'FORM VALUES' section


?>
<?php set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxxxxxxxxxxxxxxxxxxx</title>
<meta name="keywords" content="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, ">
<meta name="description" content="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ">
<link href="/inc/sheet.css" rel="stylesheet" type="text/css" />
<link href="/inc/cssmenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/inc/java.js"></script>
<link rel="stylesheet" type="text/css" href="/inc/link.css" />
<script type="text/javascript" src="/inc/java.js"></script>
<link rel="stylesheet" type="text/css" href="/inc/link.css" />
<script type="text/javascript" src="/inc/link.js"></script>
<script type="text/javascript" src="/inc/hp_cycle.js"></script>
</head>
<body>
<?php include("inc/html_head.php"); ?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="400" valign="top" style="padding:17px; width:137px;" class="menu"><?php include("services/menu.htm"); ?></td>
<td width="3" background="/img/blocks/center_shadow.gif"><img src="/img/blocks/blank.gif" width="3" height="2" /></td>
<td valign="top" style="padding:17px;" class="txt_content"><p class="productHeader">e<em>Lines</em>&trade; Quote Request Form </p>
<table width="626" border="0">
<tr>
<td width="142" align="center"><strong>STEP 1</strong></td>
<td width="40" align="center"></td>
<td width="141" align="center"><strong>STEP 2</strong></td>
<td width="40" align="center"></td>
<td width="94" align="center"><strong>STEP 3</strong></td>
<td width="40" align="center"></td>
<td width="98" align="center"><strong>STEP 4</strong></td>
</tr>
<tr>
<td><img src="../../../img/photos/elines_drawing.png" alt="elines drawing uhp" width="140" height="143" /></td>
<td><img src="../../../img/photos/arrows.png" width="40" height="20" /></td>
<td><img src="../../../img/photos/eline.png" alt="elines cad uhp welding" width="139" height="142" border="0" /></td>
<td><img src="../../../img/photos/arrows.png" alt="" width="40" height="20" /></td>
<td><img src="../../../img/photos/elines.png" alt="sdc manifold" width="93" height="142" /></td>
<td><img src="../../../img/photos/arrows.png" alt="" width="40" height="20" /></td>
<td><img src="../../../img/photos/delivery.png" alt="sdc delivery" width="85" height="76" /></td>
</tr>
<tr>
<td align="center" class="txt_content"><strong class="txt_content">Your Sketch</strong></td>
<td></td>
<td align="center" class="txt_content"><strong class="txt_content">Our CAD</strong></td>
<td colspan="2" align="right"><strong class="txt_content"> Your Manifold </strong></td>
<td align="left"></td>
<td align="center" class="txt_content"><strong class="txt_content">Your Delivery</strong></td>
</tr>
</table>
<?php if( count( $form_errors ) > 0 ) { ?>
<span>The form could not be submitted, pleace check the fields below.</span>
<ul id="formErrors">
<?php foreach( $form_errors as $error ) { ?>
<li><?php echo $error ?></li>
<? } ?>
</ul>
<?php } ?>
<form name="frmContact" method="post" enctype="multipart/form-data" action="submitform.php">
<p>For an e<em>Lines</em>™ quote, please fill in the following information:</p>
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="220" class="style2 txt_content"><strong class="sub_text">First Name:</strong></td>
<td width="314">
<input type="text" name="first_name" size="20" value="<?php echo $first_name; ?>" class="txt_content" style="width:190px;" />
</td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Last Name:</strong></td>
<td>
<input type="text" name="last_name" size="20" value="<?php echo $last_name; ?>" class="txt_content" style="width:190px;" />
</td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Company:</strong></td>
<td>
<input type="text" name="company" size="20" value="<?php echo $company; ?>" class="txt_content" style="width:190px;" />
</td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Phone:</strong></td>
<td>
<input name="phone" type="text" id="Phone" size="20" value="<?php echo $phone; ?>" class="txt_content" style="width:190px;" />
</td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Email:</strong></td>
<td>
<input type="text" name="email" size="20" value="<?php echo $email; ?>" class="txt_content" style="width:190px;" />
</td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Part Number:</strong></td>
<td><input type="text" name="part_number" size="20" value="<?php echo $part_number; ?>" class="txt_content" style="width:190px;" /></td>
</tr>
<tr>
<td class="style2 txt_content"><strong class="sub_text">Attach Drawing:</strong></td>
<td>
<div align="left">
<input type="file" value="Upload" name="image" />
</div>
</td>
</tr>
<tr>
<td><p><strong class="sub_text">How quickly would you <br/>like this part shipped?</strong></p></td>
<td>
<select size="1" name="ship_time">
<option value="1day" <?php if( $ship_method == '1day' ) echo 'selected="selected"' ?>>1 Day</option>
<option value="2days" <?php if( $ship_method == '2days' ) echo 'selected="selected"' ?>>2 Day</option>
<option value="3days" <?php if( $ship_method == '3days' ) echo 'selected="selected"' ?>>3 Day</option>
<option value="1week" <?php if( $ship_method == '1week' ) echo 'selected="selected"' ?>>1 Weeks</option>
<option value="2weeks" <?php if( $ship_method == '2weeks' ) echo 'selected="selected"' ?>>2 Weeks</option>
</select>
</td>
</tr>
<tr>
<td><strong class="sub_text">Shipping Method:</strong></td>
<td>
<select size="1" name="ship_method">
<option value="next day air early AM" <?php if( $ship_method == 'nextdayairearlyam' ) echo 'selected="selected"' ?>>Next Day Air Early AM</option>
<option value="next day air" <?php if( $ship_method == 'nextdayair' ) echo 'selected="selected"' ?>>Next Day Air</option>
<option value="next day air saver" <?php if( $ship_method == 'nextdayairsaver' ) echo 'selected="selected"' ?>>Next Day Air Saver</option>
<option value="2nd day air AM" <?php if( $ship_method == 'seconddayairsaver' ) echo 'selected="selected"' ?>>2nd Day Air AM</option>
<option value="2nd day air" <?php if( $ship_method == 'seconddayair' ) echo 'selected="selected"' ?>>2nd Day Air</option>
<option value="3 day select" <?php if( $ship_method == 'threedayselect' ) echo 'selected="selected"' ?>>3 Day Select</option>
<option value="ground" <?php if( $ship_method == 'ground' ) echo 'selected="selected"' ?>>Ground</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" class="style2 txt_content"><strong class="sub_text">Special Requirements:</strong></td>
</tr>
<tr>
<td colspan="2">
<textarea name="requirements" cols="30" rows="4" class="txt_content" style="width:100%;"></textarea>
</td>
</tr>
<tr>
<td colspan="2" class="style2 txt_content"><strong class="sub_text">How did you hear about us?</strong></td>
</tr>
<tr>
<td colspan="2" align="center">
<select size="10" name="hear_about_us" style="width:100%;">
<option value="Referral">Referral</option>
<option value="Repeat Customer">Repeat Customer</option>
<option value="Tradeshow">Tradeshow</option>
<option value="Web">Web</option>
<option value="Other" selected="selected">Other</option>
</select>
</td>
</tr>
<tr>
<td height="15" colspan="2"></td>
</tr>
<tr>
<td colspan="3" align="left"><?php
require_once('recaptchalib.php');
$publickey = "6LcsVrsSAAAAAKrP0i5bjHRhqNZoIvN2x-rzsmyD";
echo recaptcha_get_html($publickey); ?>

<input type="submit" value="Submit" />
<input type="reset" value="Reset" name="B2" />
</td>
</tr>
</table>
</form>

</table>
<?php include("inc/html_bottom.php"); ?>
</body>
 
are you testing on the same network? or do both client and server share a dns server?

the next step is to make sure that all variables look as they should. so add this at the top of your receiving script

Code:
echo '<pre>'.print_r($_POST, true) . '</pre>';

and add this after the $resp = line
Code:
echo '<pre>'.print_r($resp, true) . '</pre>';
 
So this is how you want it?

<?php
echo '<pre>'.print_r($_POST, true) . '</pre>';
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
echo '<pre>'.print_r($resp, true) . '</pre>';
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else
{
date_default_timezone_set( 'America/New_York' );

/*
Simple web form mailer
*/

//safe error-free retrival of post values
//required - do not touch or move
function pval($key){ return ( isset( $_POST[$key] ) ) ? $_POST[$key] : "" ; }


/***************************************************************
* Config Settings
***************************************************************/

//INFO FOR EMAIL
$to = 'sales@sxxxx.com';
$from = 'sales@xxxxxxxx.com';
$email_subject = 'New eLines Request Form';

//INFO FOR EMAIL TO Customer
$confirm_from = 'sales@xxxxxxxxx.com';
$confirm_email_subject = 'Thank you for submitting your eLines quote with xxx';

//Email Server Info
//disable the testing info on the production server

$smtp_server = 'mailwash27.xxxxxx.com';
$smtp_port = 225;
$smtp_username = 'ecommerce@xxxxxxxxxxx.com';
$smtp_password = 'xxxxxxxxxx';

//our list of required fields
//
// the form element 'key' or 'name' is on the left
//
// The printable title of the field is on the right
// this is used for the 'Please correct the following errors'
//
$required_fields = array(
'first_name' => "First Name",
'last_name' => "Last Name",
'company' => "Company",
'phone' => "Phone Number",
'email' => "Email Address",
'part_number' => "Part Number",
'ship_time' => "Shipping Time",
'ship_method' => "Shipping Method",
'hear_about_us' => "How did you hear about us?"
);
$required_file_fields = array(
'image' => 'Drawing Attachment'
);

//FORM VALUES
//for EVERY field you MUST have one of these. Not just required fields
// not just required fields. These are used to fill in the Email template
// and the thank you page. Also suitable for re-displaying the form
$first_name = pval('first_name');
$last_name = pval('last_name');
$company = pval('company');
$phone = pval('phone');
$email = pval('email');
$part_number = pval('part_number');
$ship_time = pval('ship_time');
$ship_method = pval('ship_method');
$requirements = pval('requirements');
$hear_about_us =pval('hear_about_us');


$thankyou = "thankyou.php";

$form = 'index.php';


$message = 'message.php';

$confirm_message = 'confirm_message.php';



$failure_notice = "There was an unknown error submitting your form. Please Call Us.";



$form_errors = array();
}

?>
 
Yes. That should provide some useful debug info.
 
I was able to figure out the problem...It was my fault, I was editing the wrong server files..I needed to edit the submitform.php file and that is not what I was doing. After editing the right server file it works fine. Thanks so much for helping
 
Ok

There are alternatives to image based captcha that are easier to implement and are also a much better user experience for your site visitors.

Just an FYI ...
 
really?? that sounds interesting...can you please tell me some of those alternatives? I have other websites where I will implement captcha but if i find other easier stuff i may just do that.
 
I will post a solution later today as my site (where my original solution was displayed) has been down for a number of months (note to self ....)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top