Are there any best practices or guidelines to follow when designing and implementing a custom Captcha solution in PHP?

When designing and implementing a custom Captcha solution in PHP, it is important to follow best practices to ensure security and usability. Some guidelines to consider include using a combination of random characters, numbers, and symbols for the Captcha challenge, implementing a time limit for completing the Captcha, and securely storing and validating the Captcha response.

<?php
session_start();

// Generate a random Captcha challenge
$captcha = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, 6);
$_SESSION['captcha'] = $captcha;

// Display the Captcha challenge to the user
echo '<label for="captcha">Please enter the following Captcha:</label><br>';
echo '<img src="generate_captcha_image.php" alt="Captcha Image"><br>';
echo '<input type="text" id="captcha" name="captcha" required>';

// Validate the user's Captcha response
if(isset($_POST['submit'])) {
    if($_POST['captcha'] == $_SESSION['captcha']) {
        echo 'Captcha validation successful!';
    } else {
        echo 'Incorrect Captcha, please try again.';
    }
}
?>