CaptchaGen - Methods
Back to CaptchaGen
The CaptchaGen script is more like a perl module in that it needs to be 'required' by your main script. When you purchase CaptchaGen you will recieve a basic example script that do this but it is as simple as adding a few lines to the beginning of your main script and then add calls to the respective subroutines as needed.
You can see the example working at http://captchagen.cgiscripts4u.com/cgi-bin/captchagenexample.cgi, it initially presents the user with a Log In form and once it is submitted it checks the captcha entered is correct. The example does no more but if you have a basic knowledge of perl you will easily see from the code how to incorporate it into your existing scripts.
Including CaptchaGen image in your forms
Adding the Captcha image to your forms can be done in three ways depending on your server and form.:
SSI
If your server allows SSI calls then this creates the image in a table row and the text with text box in the next table row. It also loads the relevant javascript needed for the 'Refresh Image' button.
ie : <!--#include virtual="/pathto/yourscript.cgi"-->
returns :
Software error:
Can't locate Digest/SHA1.pm in @INC (you may need to install the Digest::SHA1 module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /var/www/cgiscripts4u.com/private/captchadata/captchagen.pl line 17.
BEGIN failed--compilation aborted at /var/www/cgiscripts4u.com/private/captchadata/captchagen.pl line 17.
For help, please send mail to the webmaster (webmaster@cgiscripts4u.com), giving this error message
and the time and date of the error.
Software error:
[Sun May 28 03:01:59 2023] captchagenexample.cgi: Can't locate Digest/SHA1.pm in @INC (you may need to install the Digest::SHA1 module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /var/www/cgiscripts4u.com/private/captchadata/captchagen.pl line 17.
[Sun May 28 03:01:59 2023] captchagenexample.cgi: BEGIN failed--compilation aborted at /var/www/cgiscripts4u.com/private/captchadata/captchagen.pl line 17.
Compilation failed in require at captchagenexample.cgi line 38.
For help, please send mail to the webmaster (webmaster@cgiscripts4u.com), giving this error message
and the time and date of the error.
Javascript
If SSI is not an option then it can be called using javascript, this just returns the image and code required when the 'Refresh Image' button is depressed. ie in your form you would have something like:
<form action='/pathto/yourscript.cgi'>
.....
<tr><td>
<img id='captchaimage' name='captchaimage' src='/loading.gif'/>
</td>
<td>
<input type=button value='Refresh Image' onclick='RefreshCaptcha();return false;'>
</td></tr>
<tr><th>Type in the characters you see above</th>
<td>
<noscript>
Sorry as you do not have javascript enabled you are unable to use the captcha.
</noscript>
<input type="hidden" name="captchacoded" id="captchacoded" value=''>
<input type="text" name="captcha" id='captcha' />
</td></tr>
<tr><td colspan="2"><span id="captchasound"></span></td></tr>
...
</form>
<script src='/pathto/yourscript.cgi?jscaptcha=1' type='text/javascript'></script>
<script>
RefreshCaptcha();
</script>
Which will return :
From within another perl script
If your form is generated by a perl script you can 'require' the CaptchaGen script and call a subroutine which will return a code. Use this code to link to the image generated. See the 'captchagenexample.cgi' example included with the script or take a look at the Installation Instructions.