Skip to content

Download CAPTCHA system in PHP

February 5, 2021
Create a CAPTCHA in PHP.

In this post I will show you how you can create your own antispam system, making a CAPTCHA in the PHP programming language. ENTERS!


I come again with another tutorial for programmers, and today we are going to learn how to create a CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart, for its acronym in English), and it is an antispam system to prevent SPAM or prevent the access to robots of the access to a certain place or execution of a certain action, so if you need a CAPTCHA, you are in the right place.

Explanation of this file:

This system is divided into 3 files:

  • index.php (contains a test form).
  • captcha.php (generates an image that has a random text).
  • validar.php (gets what to do if the captcha is correct or not).

IF YOU DO NOT WANT to copy the codeAt the bottom of this post I leave you a download link to the source files of the code.

Index.php file:

<!DOCTYPE html><!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>Aprendiendo algo con Master Coria</title> <script src=""></script> <script> $(function(){ $("btn_recargar").click(function(){ document.location.reload(); return false; }); $("#btn_iniciar").click(function(e){ e.preventDefault(); var data = $('#frm').serialize(); $.ajax({ url: "validar.php", type: "post", data: data, success: function(res){ alert(res); } }); }); }); </script> </head> <body> <form id="frm" action=""> <table> <tr> <td>Usuario: </td><td><input type="text" name="user" /></td> </tr> <tr> <td>Password: </td><td><input type="text" name="pass" /></td> </tr> <tr> <td><img src="captcha.php" /></td><td><input type="text" name="captcha" /></td><td><button id="recargar">Recargar</button></td> </tr> <tr> <td><input type="submit" id="btn_iniciar" value="Login" /></td> </tr> </table> <input type="hidden" name="trp-form-language" value="en"/></form> </body></html>

Captcha.php file:

<?php header("content-type: imagen/png"); $imagen = imagecreate(90, 50); $color_fondo = imagecolorallocate($imagen, 59, 66, 255); $color_texto = imagecolorallocate($imagen, 255, 255, 255); function generar_caracteres($chars, $length){ $captcha = null; for($i=0;$i

Now this is the validar.php file:

If you want to understand the total operation of this system, I leave you the 2 video tutorials of the youtuber «PuroCode» (I also leave you the source code in case you want to have it ordered at the bottom of the page):

We recommend you:  How to change the WiFi password from the router



Download CAPTCHA system in PHP:

to downloadDownload source code

Note: the links contained here are shortened using our link shortener (Master Coria URL Shortener).

Doubts questions?
I hope I have helped you and I hope you are done with the post. If you don't understand something, contact our team using the floating chat (located in the lower right part of your screen) to leave us your question.

You can see our most recent posts on our page start from the blog. Like us on our Facebook page so you don't miss any news.