Php kullanarak bu web düğmeye captcha'yı ekle

1 Cevap php

Ben henüz tam olarak anlamıyorum bazı php kodu ile bir sayfa var

Ve ben üzerinde oldukça iyi bir kolu olduğunu düşünüyorum recaptcha kullanarak bir php pasajı var.

Ben henüz iki entegre nasıl emin değilim.

Ben bu olayı tetikleyen Captcha kodu görmek ama Captcha yapılır kadar düğmesine engellemek için nasıl emin değil im.

Varolan kodu:

<div id="colOne">
<h2>Contact Us</h2>
<form action="gdform.php" method="post"> 

<table border="0" cellpadding="2" cellspacing="2" summary="feedback form" align="center">
<tbody>
<tr>
<td colspan="2">
<p>Please fill out the fields below with your information and your question
    		<br />or comment and we will get back to you as soon as possible.</p>
</td>
</tr>
<tr>
<td align="left">Name:<span style="color: #ff0000;">*</span></td>
<td><input type="text" name="name" size="25" /></td>
</tr>
<tr>
<td align="left">Email Address:<span style="color: #ff0000;">*</span></td>

<td><input type="text" name="email" size="25" /></td>
</tr>
<tr>
<td align="left">Phone:</td>
<td><input type="text" name="phone" size="25" /></td>
</tr>
<tr>
<td align="left">Subject:<span style="color: #ff0000;">*</span></td>
<td><input type="text" name="subject" size="25" /></td>
</tr>
<tr>
<td colspan="2" align="left">Comments: <span style="color: #ff0000;">*</span><br /><textarea rows="20" cols="50" name="comments"></textarea></td>

</tr>
<tr>
<td colspan="2" align="center"><span style="color: #ff0000;">*</span> Required Fields</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="Send Request" /><br /></td>
</tr>
</tbody>
</table>
</form></div>

Ben CAPTCHA kodu

EDIT: THIS IS NO MY KEY.......PLEASE DO NOT WORRY.......NOT MY KEY, IT IS FAKE........EVERYTHING IS OKAY

<form action="" method="post">
<?php

    function sendmail()
    {
      echo "you got it";
    }

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LeWIAgAAAAAAPA9picBEVB18lDgGVIOIav";
$privatekey = "6LeWIAgAAAAAABViAnDjvKXxWtJGBoRaWXe";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
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!";
    			sendmail();

        } 
    	else 
    	{
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" value="submit" />
    </form>

1 Cevap

Her şeyden önce, sorunuzun içinde ReCAPTCHA özel anahtar dahil, ve bu her zaman güvenli CAPTCHA tutmak için özel tutmalı şey.

İkincisi, siz dahil kod kaptan değil, bu formda görüntülemek yapmak için kod için işlem kodudur. Eğer ekrana CAPTCHA istiyorum bu kodu koymak gerekir:

require_once('recaptchalib.php');
$publickey = "..."; //enter your public key here
echo recaptcha_get_html($publickey);

Diğer blok sizin formun eylem tarafından işleme sayfa bakılırsa üstünde gitmek zorunda, bu gdform.php bulunuyor:

require_once('recaptchalib.php');
$privatekey = "...";
$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 . ")");
}

Tabii ki, bu herhangi bir iş için, ayrıca ReCAPTCHA PHP kütüphanesi ve kendi özel / ortak anahtar çifti olması gerekir. Eğer bu yoksa, reCAPTCHA sitesinden onları.

Daha fazla bilgi için, reCAPTCHA PHP Quickstart okuyun.