integrating Google reCaptcha into mail.php

A

Anonymous

Guest
Hi guys

Sorry for this but I am stuck. I am lost with regards to php and although I can implement the html side of things, I dont have a clue where to place the recaptcha scripting in the php. Can anyone help me? Happy to pay for assistance. Cheers, Glenn

Its this part:

When your users submit the form where you integrated reCAPTCHA, you'll get as part of the payload a string with the name "g-recaptcha-response". In order to check whether Google has verified that user, send a POST request with these parameters:
URL: https://www.google.com/recaptcha/api/siteverify
secret (required) 6LetXCYUAAAAACAn2FncL1ycHTEwwhA729jerj4N
response (required) The value of 'g-recaptcha-response'.
remoteip The end user's ip address.
 
I recently started programming and recently faced the same problem on my site. thanks for the answer
 
Here's how I do it ->
Code:
$submit = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($submit) && $submit === 'submit') {
    /* The Following to get response back from Google Recaptcha */
    $url = "https://www.google.com/recaptcha/api/siteverify";
    /* Remote Server  */
    $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL);
    /* The response you get back from Google verifying the user is indeed a human */
    $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer);
    /* Put it in a form that PHP can understand */
    $recaptcha_data = json_decode($response);
    /* The actual check of the recaptcha */
    if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { // Success 
        $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

        $send = new Email($data);
    } else {
        $success = "You're not a human!"; // Person is not a HUMAN...
    }
}
 
Back
Top