| Getting started with CAPTCHA | |
By Rodney Amato |
Published
07/19/2006
|
Programming
|
Rating:
![]() ![]() ![]() ![]()
|
|
|
A CAPTCHA ExampleWhen someone first visits the page on your site that you want to protect with CAPTCHA, we generate a code and store it in the session. This is the code that we want to generate the CAPTCHA image with. In our form near the text field we include an image tag which references a PHP script instead of an image on the server.
* generateSecret This PHP script will dynamically generate our image for us and also increment a counter in the session. Why keep a counter? Well, without a counter it would be easy to work out the code once and then submit it with different details but the same code over and over again. By checking to make sure this counter isn't over 1 (assuming we set it to 0 when we generate the secret) when we generate the image, we can be sure that this type of attack can't happen. if ($_SESSION['captchaLoads'] > 1) { We also append a random string or code to the image url as part of a get string. Your script can easily ignore this but by adding it we can avoid the problem where the web browser might cache the captcha image. <img realrealrealrealrealsrc="captchaimage.php?879327def" src="http://www.interspire.com/content/admin/captchaimage.php?879327def" src="http://www.interspire.com/content/admin/captchaimage.php?879327def" src="http://www.interspire.com/content/admin/captchaimage.php?879327def" src="http://www.interspire.com/content/admin/captchaimage.php?879327def" alt="CAPTCHA image" /> The last thing to take into account is that you don't really want the web browser to autocomplete on the captcha field so we need to disable autocompletion for that field. Your normal input field would look like
<input type="text" name="captcha" id="captcha" value="" /> We can disable autocomplete easily by adding the autocomplete=”off” property
<input type=”text” name=”captcha” id=”captcha” value=”” autocomplete="off" />
This method however causes the HTML to not validate completely since autocomplete is a non w3c approved property. To get around this we can disable it with javascript.
<script type="text/javascript"> |
|
or 02-9262-7770 


