What are the best practices for integrating FriendlyCaptcha into a PHP website to prevent spam attacks on forms?

To prevent spam attacks on forms in a PHP website, it is recommended to integrate FriendlyCaptcha, a user-friendly CAPTCHA solution that helps verify human users. By adding FriendlyCaptcha to your forms, you can effectively block automated bots from submitting spam.

// Include the FriendlyCaptcha JavaScript library in your HTML
<script src="https://cdn.friendlycaptcha.com/friendlycaptcha.js"></script>

// Add the FriendlyCaptcha widget to your form
<div class="frc-captcha" data-sitekey="YOUR_SITE_KEY"></div>

// Validate the FriendlyCaptcha response on form submission
if(isset($_POST['submit'])){
    $response = $_POST['frc-response'];
    $verification = file_get_contents("https://friendlycaptcha.com/api/v1/siteverify?secret=YOUR_SECRET_KEY&response=".$response);
    $verification = json_decode($verification);
    
    if($verification->success){
        // Process form submission
    } else {
        // Display error message or handle the spam submission
    }
}