What are potential pitfalls to avoid when using captchas in PHP scripts?

One potential pitfall to avoid when using captchas in PHP scripts is not properly validating the captcha input from the user. This can lead to bots easily bypassing the captcha and submitting forms. To solve this issue, always validate the captcha input against the generated captcha code before allowing form submission.

// Validate captcha input
session_start();
if(isset($_POST['captcha_input']) && $_POST['captcha_input'] === $_SESSION['captcha_code']) {
    // Captcha input is correct, proceed with form submission
} else {
    // Captcha input is incorrect, display error message
    echo "Captcha input is incorrect";
}