Bootstrap FreeKB - PHP - Create a captcha
PHP - Create a captcha

Updated:   |  PHP articles

Let's first look at creating a really simple captcha, where will will generate a random string of characters. 

<?php
  $system_captcha = substr( md5(rand()), 0, 5);
?>

 

This will produce a random string, such as a5ecf. We can then create a form, where we will pass both the system captcha and user captcha to form_data.php.

<form method="post" action="form_data.php">
  <input type="hidden" name="system_captcha" value="<?php echo $system_captcha; ?>">
  <input type="text" name="user_captcha">
</form>    

 

When the form data is being processed, the user supplied captcha can be compared to the system captcha.

<?php 
  $user_captcha   = $_POST["user_captcha"];
  $system_captcha = $_POST["system_captcha"];

  if ($user_captcha == $system_captcha) {
    //Success markup
  }
  else {
    //Failure markup
  }
?>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 66633e in the box below so that we can be sure you are a human.