2016-03-20 23 views
1

Çok basit görünüyor, website'a bir Google recaptcha ekledim, HTML kodlarına aşağıdakileri ekledim. Ancak, kişi formu doldurabilir ve captcha tamamlamadan posta gönderebilir. Ancak, kişi formu doldurabilir ve captcha tamamlamadan posta gönderebilir. (Bu yüzden, sadece düz bir şekilde çözebildiğim herhangi bir bulmacayı çözmemek zorunda kalmazlar). Bu, elbette, botları kurcalamayacak bir şekilde bırakabilirler.Google Recaptcha (PHP)

Temelde, kullanıcıların aslında "Ticked" olup olmadığını kontrol eden PHP koduna ihtiyacım var. Recaptcha "Tamamlandı". Böylece posta göndermeye devam edebilirler.

My PHP kodu: Gerçekten PHP'de kodu nasıl hiçbir ipucu var

if ($_POST['submit']) { 
     if ($email != '') { 
      if ($human == '4') {     
       if (mail ($to, $subject, $body, $from)) { 
        echo '<p>You have successfully submitted your information to PS4RS. Subscribers to our mailing list will begin to periodically receive updates.</p>'; 
       } else { 
        echo '<p>Something went wrong, go back and try again!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
       } 
      } else if ($_POST['submit'] && $human != '4') { 
       echo '<p>You answered the anti-spam question incorrectly!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
      } 
     } else { 
      echo '<p>You need to fill in all required fields!!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
     } 
    } 
?> 

, bu benim en iyi girişimidir.

+3

yardımcı


Umut https://developers.google.com/recaptcha/eski/docs/php # hızlı başlangıç). İlk önce şunu ver. – Ohgodwhy

+0

@brimstone Hayır. Bu sadece mevcut formu için onun PHP'si, orada Google Recaptcha ile ilgisi yok. – Ohgodwhy

+0

[Google it] (https://www.google.no/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#safe=active&q=google+recaptcha+example) örneklerini görürseniz Google reCAPTCHA'yı kodunuza nasıl uygulamanız gerekir. – Qirel

cevap

1

yardım ederse

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

    if (!$resp->is_valid) { 
     // What happens when the CAPTCHA was entered incorrectly 
     die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
    "(reCAPTCHA said: " . $resp->error . ")"); 
    } else { 
     // Your code here to handle a successful verification 
    } 
?> 

söyle. Bu cevabı here

senin amaç için bu kadar
<?php 
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=". $yoursecret."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']); 
    $googleobj = json_decode($response); 
    $verified = $googleobj->success; 
    if ($verified === true){ 
    //do stuff 
    } 

...

<?php 
if($_POST['submit']) { 
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=". $yoursecret."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']); 
    $googleobj = json_decode($response); 
    $verified = $googleobj->success; 
    if($verified === true) { 
    if(mail($to, $subject, $body, $from)) { 
     echo '<p>You have successfully submitted your information to PS4RS. Subscribers to our mailing list will begin to periodically receive updates.</p>'; 
    } else { 
     echo '<p>Something went wrong, go back and try again!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
    } 
    } 
} 
?> 


$yoursecret

İÇİN GİZLİ ANAHTAR IN ADD EMİN OLUN bulundu

(Yani sitesi anahtarından farklı) Bunu [belgelerinden sunucu tarafı doğrulama içinde] bir şey (uygulamayan

+0

amortismana uğruyor çok temel kod :) – alpc

-1

Bu resmi Google dev web sayfasından: Ben onu alıntı gidiyorum yani bu Bu benim orijinal cevap değil

+0

cevabını bulamıyorsunuz php api – krummens

İlgili konular