0

Hope someone could help..i have got the widget to show for the no captcha recaptcha and i have found a code on the internet that i am trying to use because i am not that good with php but it seems to work only partially. everytime that i click the box or that i dont and i try to send an email it says please check the captcha.

this is what i have in my mail confirm.php file which is the server side (i dont think theres a need to post the widget code as it shows and works, which is step 1)

$email;$message;$sujet;$header;$captcha;
    if(isset($_POST['email'])){
      $email=$_POST['email'];
    }if(isset($_POST['message'])){
      $email=$_POST['message'];

}if(isset($_POST['sujet'])){
      $email=$_POST['sujet'];
}if(isset($_POST['header'])){
      $email=$_POST['header'];


    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form.</h2>';
      exit;
    }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcIAgETAAAAAEjbARzUsrkgBIHAeE8QmsNE3US-&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)
    {
      echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }
    else
    {
      echo '<h2>Thanks for posting comment.</h2>';
    }
5
  • 1. you're not sanitizing your post's correctly. This is a serious security flaw. 2. what do you do with the email variable? If you are trying to make it body, you would use $email += to keep adding to the end of the variable. 3. when you are checking the Boolean type, use === in PHP $response.success === false
    – phpmeh
    Apr 13, 2015 at 1:01
  • For love of anything use ELSE statements. I don't know where you found this code but it is just horrid... Apr 13, 2015 at 4:00
  • im not good with php so if you could suggest a fix for this that would be greatly appreciated:) @phpmeh
    – Essentialz
    Apr 13, 2015 at 23:00
  • like i said to phpmeh im not too good with php so do you have any suggestions like any lines that i can change or add to better it? @ViruZX
    – Essentialz
    Apr 13, 2015 at 23:01
  • I'll just pass you one of my integrations... hold on. Apr 14, 2015 at 0:43

1 Answer 1

2

Modify this code to your desires.

<?
    $APIkey = "API KEY";
    $postresult=$_POST['g-recaptcha-response'];
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$APIkey&response=$postresult");

    if (strpos($response, 'true')){
        //Captcha is valid, do whatever.
    } else {
        //Captcha is invalid. Tell them to go away.
    }

?>
7
  • hi Slava ive tried you code but now it just send an email whether or not i click the captcha :S and the only thing that i did was add my secret key in the "API KEY" section and secret= part
    – Essentialz
    Apr 21, 2015 at 15:21
  • @Essentialz It shouldn't... try using !strpos($response, 'false') instead. if that doesn't work, review how your form is built. Apr 21, 2015 at 15:35
  • hi Slava! i will try that now and i will let you know what happens...thank you for the help so far:)
    – Essentialz
    Apr 21, 2015 at 15:46
  • yeah im not having any luck Slava, its always give the captcha is invalid message which I made as F**k off spammer and it always says email sent succefully which is another echo in the contact php page and this happens whether I click the captcha or not..i get the same two messages and the email always sends:S
    – Essentialz
    Apr 21, 2015 at 17:33
  • @Essentialz At this point this is quite strange. Mind pasting the entire code somewhere so I can take look? Apr 21, 2015 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.