Using Division Equations to Make Web Forms Safer with Ajax - Using division equations as challenge strings (Page 3 of 4 )
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.