Using division equations as challenge strings - AJAX
From a web developerís point of view, building a mechanism that permits you to protect online forms against attacks by spam bots, malicious automated submissions, and so forth, can be challenging. Developing such an application often requires using a server-side graphic library to generate the so-called noisy images. However, itís possible to quickly create a similar mechanism with Ajax, without having to work directly with images generated in the web server. This is the fourth part of a four-part series that explains how to do just that.
In order to modify the Ajax application shown in the previous segment, and make it capable of generating division equations within a specific web form, Iím going to redefine one of its source files -- specifically, the one called ďget_checkingcode.php.Ē Once modified, this file will be charged with generating the proper division equations, in this way implementing a simple protection system.
That being said, hereís the brand new definition of this PHP file. Have a look at it, please:
echo $valuea.' % 2';
Indeed, the above file is extremely easy to follow. It simply generates challenge division equations, where the dividend will always be a random pair of integers. In this case, I decided to divide this number by 2, in order to construct simple operations, but naturally this option can be modified to fit other requirements.
So far, so good. Having modified the signature of the ďget_checkingcode.phpĒ PHP file, the Ajax program that you saw before now has the capacity to generate division equations in the form of challenge strings. Thus, provided that you've grasped how this file functions, itís time to see how it can be directly coupled to an HTML form to turn this protection mechanism into a fully-functional application.
Therefore, go ahead and read the next section. Itís only one click away.