One way to combat "bots" that automatically fill in web forms is by using the CAPTCHA technique. This shows the user an image with some random letters; the user must fill in a text field with those letters. In this recipe, we will create a CAPTCHA image and verify that the user has entered it correctly.
We need a standard Laravel installation and make sure we have the GD2 library installed on our server, so we can create an image.
To complete this recipe, follow these steps:
In our
app
directory, create a directory namedlibraries
, and in ourcomposer.json
file, update it as follows:"autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/libraries" ] },
In our
app/libraries
directory, create a file namedCaptcha.php
to hold our simpleCaptcha
class:<?php class Captcha...