What is the purpose of using reCAPTCHA in PHP forms?

reCAPTCHA is used in PHP forms to prevent spam and automated submissions. It helps verify that the form is being filled out by a human and not a bot. By implementing reCAPTCHA, you can improve the security of your forms and ensure that only legitimate submissions are accepted.

<?php
// Include the reCAPTCHA library
require_once('recaptchalib.php');

// Your reCAPTCHA site key
$siteKey = 'YOUR_SITE_KEY';

// Your reCAPTCHA secret key
$secret = 'YOUR_SECRET_KEY';

// Verify the reCAPTCHA response
$recaptcha = new ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response']);

if ($resp->isSuccess()) {
    // Process the form submission
    // Your code here
} else {
    // Handle reCAPTCHA verification failure
    echo 'reCAPTCHA verification failed.';
}
?>