Jump to content

Captcha


ben3001

Recommended Posts

I have found where i didnt close it, it was on line 56, now im back to where the form submits regardless of the captcha.

<?php$name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from [url="http://recaptcha.net/api/getkey"]http://recaptcha.net/api/getkey[/url]$publickey = "6LcFHwAAAAAAAFyCHo-h-t65VHyvye-yL9VDhFtY";$privatekey = "6LcFHwAAAAAAAE22y6Z62EprK2oyTg9NNjGVl07h";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){global $publickey;if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])){$incorrectEmail="";}else{$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}if ($_POST["recaptcha_response_field"]) {$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);}if ($resp->is_valid) {echo "You got it!";} else {# set the error code so that we can display it$error = $resp->error;}echo recaptcha_get_html($publickey, $error);print '<span class=style4>Enquires</span><p>Problem with the site? Need more information? Complete the form below,if you have entered your email address correctly you should recieve an automated reply confirmingyour query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"><!--document.myForm.myField.disabled=true;//--></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/>';print '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td></tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><tr><td>Verification:</td><td>' . recaptcha_get_html($publickey, $error) . '</td></tr><table border="0" width="100%"><tr><td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td></tr></table></form></table>';}if ( isset ($_POST['submit'])){$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){ }else{$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)){print"";printit();}else{ mail("b_e_n04@hotmail.com","Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]From: $nameEmail Address: $EmailMessage: $Comment","From:$Email");mail("$Email","Auto Reply Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]Dear: $nameThank you for contacting me regarding [url="http://www.aquatic-management.org"]http://www.aquatic-management.org[/url]. Your enquiry is shown below.'$Comment'I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.Once again thank-you for your enquiry.Ben Davies","From:b_e_n04@hotmail.com");print "<span class=style4>Thank you for your enquiry</span><br><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p><strong><p>Website design regarding:</strong> [url="http://www.aquatic-management.org<p/>"]http://www.aquatic-management.org<p/>[/url]<strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p><strong><p>Enquiry:</strong> $Comment</p>";}}else { // Display the form.printit();}?>

Link to comment
Share on other sites

Yeah, that's what the code says. You need to read through the code and understand it, it will be quicker then doing the back and forth. It looks like it doesn't have any indenting, so you will probably want to reformat the code so that the logical structure matches what you see in the text. That way when you read through it you can easily see which if blocks the different pieces of code are in. Obviously you want the captcha code to be executed when the form gets submitted and the email stuff gets processed, but it's hard to identify where that is in the code when there is no indenting. I haven't changed anything in the code, but I have indented it for you:

<?php$name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey$publickey  = "6LcFHwAAAAAAAFyCHo-h-t65VHyvye-yL9VDhFtY";$privatekey = "6LcFHwAAAAAAAE22y6Z62EprK2oyTg9NNjGVl07h";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){  global $publickey;  if ( isset ($_POST['submit']))  {	$incorrectCustomer="";	$incorrectEmail="";	$incorrectDate="";	$incorrectComment="";		if($_POST['Name']==null)	{$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}		else	{$incorrectCustomer="";}		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email']))	{$incorrectEmail="";}		else	{$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}		if($_POST['Comment']==null)	{$incorrectComment="<span style='color:#FF0000'> * Required</span>";}		else	{$incorrectComment="";}  }  if ($_POST["recaptcha_response_field"])   {	$resp = recaptcha_check_answer ($privatekey,	  $_SERVER["REMOTE_ADDR"],	  $_POST["recaptcha_challenge_field"],	  $_POST["recaptcha_response_field"]);  }  if ($resp->is_valid)   {	echo "You got it!";  }   else  {	# set the error code so that we can display it	$error = $resp->error;  }  echo recaptcha_get_html($publickey, $error);  print '<span class=style4>Enquires</span>  <p>Problem with the site? Need more information? Complete the form below,  if you have entered your email address correctly you should recieve an automated reply confirming  your query has been recieved . All emails are replied to within 24 hours.</p>  <script language="JavaScript"><!--  document.myForm.myField.disabled=true;  //--></script>  <form name="Contact Us" action="design2.php" method="post">  <table style= width="100%" border="0" cellpadding="3" cellspacing="1">  <tr>  <td width="20%"><p align="left">Website design regarding:</p></td>  <td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/>';print '</td>  </tr>  <tr>  <td width="20%">Name:</td>  <td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td>  </tr>  <tr>  <td>Email:</td>  <td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td>  </tr>  <tr>  <td>Enquiry</td>  <td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td>  </tr>  <tr>  <td>Verification:</td>  <td>' . recaptcha_get_html($publickey, $error) . '</td>  </tr>  <table border="0" width="100%">  <tr>  <td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td>  </tr>  </table>  </form>  </table>  ';}if ( isset ($_POST['submit'])){  $validEmail=true;  $validNumber=true;  if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))  { }  else  {$validEmail=false;}  if(($name==null)||($validEmail==false)||($Comment==null))  {	print"";	printit();  }  else  { 	mail("b_e_n04@hotmail.com","Website Design: http://www.aquatic-management.org","	From: $name	Email Address: $Email	Message: $Comment","From:$Email");  	mail("$Email","Auto Reply Website Design: http://www.aquatic-management.org","	Dear: $name  	Thank you for contacting me regarding http://www.aquatic-management.org. Your enquiry is shown below.  	'$Comment'  	I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.  	Once again thank-you for your enquiry.  	Ben Davies","From:b_e_n04@hotmail.com");	print "<span class=style4>Thank you for your enquiry</span>	<br><p>Comments are always welcomed and replied to within 2-3 days.</br></font>	<p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p>	<strong><p>Website design regarding:</strong> http://www.aquatic-management.org<p/>	<strong><p>Name:</strong> $name<p/>	<strong><p>Email address:</strong> $Email</p>	<strong><p>Enquiry:</strong> $Comment</p>  	";  }}else { // Display the form.  printit();}?>

Link to comment
Share on other sites

You can't really refresh an image, but you can change the source. I'm not sure if anything happens if you set the source to the same thing. In Javascript, an image object will have a src property that you can use to set or read the source of the image. You can always add an extra number to the URL to make it different, like this:verify.php?num=123

Link to comment
Share on other sites

so how do other captchas work? currently the only way i have of refreshing the captcha is by pressing a button that refreshes the whole page, however, this obviously looses the data inputted into the form

Link to comment
Share on other sites

Right, the refresh link is just a link to the page, that's what happens. If you don't want to refresh the page, you need to have the link call a Javascript function:<a href="java script:void(0);" onclick="refresh_captcha();">And then then refresh_captcha function can generate a random number to stick on the end of the verify.php file and update the source of the captcha image. That will update the image, but I don't know if that will break the captcha, I'm not sure if the form will check for the old or the new image. You'll have to test that. If the verify.php page sets a session variable or something like that, it may work.

Link to comment
Share on other sites

Sorry but i dont really understand what i must do.this is the code i have for the captcha field

<tr>		<td>Verification Code</td>		<td><br /><img src="verify.php" alt="captcha" /><a href="design.php?num=1">Refresh </a><br />Enter the verification code as it is shown in the box above.<br />				<input id="cpt" name="captcha" type="text" size="10" maxlength="5" />'; if( $incorrectCaptcha) print " <span style='color:#FF0000'> Invalid code. Try again!</span>"; print '</td>		</tr>

Link to comment
Share on other sites

<script type="text/javascript">function refresh_captcha(){  document.getElementById("captcha").src = "verify.php?" + Math.random();}</script><img src="verify.php" alt="captcha" id="captcha" /><a href="java script:void(refresh_captcha())">Refresh </a>

make sure to remove the space between java and script.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...