HomeAJAX & Prototype Page 3 - Using Division Equations to Make Web Forms Safer with Ajax
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:
<?php
session_start();
$valuea=rand(1,10)*2;
$_SESSION['checkcode']=$valuea/2;
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.