How to Implement CAPTCHA With PHP and GD
By [http://ezinearticles.com/?expert=Andrew_Ivanov]Andrew Ivanov
So, you have a public submission form on your website (contact page, forum submission,blogs comment form) and need to prevent spam by auto-submitters. Common way to do this is to implement CAPTCHA - an image with randomly generated string
(quote from Wikipedia, free online enciclopedia: “A CAPTCHA is a type of challenge-response test used in computing to determine whether the user is human. "CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart", trademarked by Carnegie Mellon University.”)
Simple, quick and efficient PHP solution for implemet CAPTCHA:
the advantage of this solution: it is easy to read symbols by human and automated captcha processor software, but hard to process the image by computer because common CAPTCHA processors can't understand which one of the outputted symbols it must ignore!
obviously you need PHP engine enabled for your webserver, for execute PHP scripts, and GD (PHP graphics library) for generate the image. Webserver, PHP and GD versions are no matter, the solution below is tested for Apache(Windows and Unix), IIS(Windows), PHP-4, PHP-5, GD, GD2
1) Make a PHP script (separate file captcha.php) which will generate the CAPTCHA image:
[?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
function _generateRandom($length=6){
$_rand_src = array(
array(48,57) //digits
, array(97,122) //lowercase chars
// , array(65,90) //uppercase chars
);
srand ((double) microtime() * 1000000);
$random_string = "";
for($i=0;$i
Wednesday, October 31, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment