How to use Honeypot to prevent from robots in Codeigniter 4 | Security Feature

Fetching Comments ...
How to use Honeypot to prevent from robots in Codeigniter 4 | Security Feature

Honeypot Class in Codeigniter 4

Honeypot Class makes it possible to determine when Bot make request using form in Codeigniter 4 project. This can be enabled inside ”Application\Config\Filters.php” file of CI4 project. By attaching a hidden field in every form inside your CI4 project automatically. This hidden field is not visible to users but accessible to Bots. So when ever this field’s value is not empty then CI4 throw ”HoneypotException” and crash the webpage to abort request made by Bot and prevents your CI4 project from spam.

How to enable Honeypot in Codeigniter 4

To enable Honeypot class in your CI4 project you have to modify ”app/Config/Filters.php” file. Just uncomment ’honeypot’ options from ”$globals” array. Do the following change in this file. (If you don’t understand how to do this then you can watch our Youtube video, Video link is in the end of this post).

After making the above change your CI4 project is ready to protect from spam. You don’t have to do anything with this. But you can customize settings according to your need which is totally optional.

Configuring Honeypot

Honeypot can be customized. The fields below can be set either in app/Config/Honeypot.php or in .env.

  • hidden - true|false to control visibility of the honeypot field; default is true
  • label - HTML label for the honeypot field, default is ‘Fill This Field
  • name - name of the HTML form field used for the template; default is ‘honeypot
  • template - form field template used for the honeypot; default is ‘{label}

Video tutorial of Honeypot class

Github project link

You can get full source code of this project from github here

Featured Posts

post preview
post preview
post preview
post preview
post preview


Related Posts

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.