Home arrow PHP arrow Page 4 - Improve PHP Captcha with Optical Character Recognition Tests

The final script - PHP

If you're working on a captcha system for your PHP-based website, you may be faced with an interesting challenge. How do you make your system too hard for spam bots to read, but not too hard for humans? This is especially worrying in the wake of bots that can harness OCR for reading captchas. This article explains how to increase the difficulty of a captcha system and test it to make sure it meets your requirements.

TABLE OF CONTENTS:
  1. Improve PHP Captcha with Optical Character Recognition Tests
  2. Adding background noise to captcha
  3. Increasing captcha difficulty
  4. The final script
By: Codex-M
Rating: starstarstarstarstar / 4
August 02, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The final script is shown below:

<?php

 

session_start();

 

$stringgen = mt_rand(1000, 9999);

 

$_SESSION['answer']=$stringgen;

 

$imagecreate = imagecreate(50, 50);

 

$background = imagecolorallocate($imagecreate, 0, 0, 255);

 

$textcolor = imagecolorallocate($imagecreate, 255, 255, 255);

 

for ($c = 0; $c < 200; $c++){

 

   $x = rand(0,50-1);

 

   $y = rand(0,50-1);

 

   imagesetpixel($imagecreate, $x, $y, $textcolor);

 

   }

 

$xlocation = rand(1,10);

 

$ylocation = rand(1,10);

 

imagestring($imagecreate, 5, $xlocation, $ylocation, $stringgen, $textcolor);

 

header("Content-type: image/png");

 

$image= imagepng($imagecreate);

 

?>

Conclusions and Recommendations

There are still a lot of ways to increase the difficulty of captcha, such as distorting the text or having the characters appear connected to each other. However, this system can also substantially increase the difficulty humans will experience in solving it, and even humans can commit frequent mistakes when answering this type of challenge.

As shown in this tutorial, simply increasing the background noise can make the OCR unable to solve the challenge properly without necessarily adding too much difficulty for humans.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: