/ Published in: PHP
URL: http://it-ride.blogspot.com/2009/08/captcha.html
Please visit the URL of this snippet to see how these captchas look.
Expand |
Embed | Plain Text
<?php $W = 160; // width $H = 60; // height $L = 6; // length of the key $BG = 'light'; // can be 'light' or 'dark', accorting to the background color of // the page it will be on $F = './DejaVuSans.ttf'; // path to true-type font file function makeKey($length) { // generate a random sequence of characters $a = 'abcdefghijklmnopqrstuvwxyz'; $s = ''; for ($i=0; $i < $length; $i++) { } return $s; } $img = imagecreatetruecolor($W, $H); // make the image alpha-aware imagesavealpha($img, true); // make colors 'blend', not overwrite imagealphablending($img, true); // make the image transparent imagefill($img, 1, 1, imagecolorallocatealpha($img, 0, 0, 0, 127)); // generate two random colors and decide which one goes where if ($BG == 'dark') { } else { } // write background static for ($i=0; $i < 15; $i++) { imagettftext($img, 12, $angle, 0, $i*15, $bg_color, $F, makeKey(30)); } $key = makeKey($L); // you should store this in the user session to check it later // write the actual key, in two parts // output the image imagepng($img); ?>
Comments
Subscribe to comments
You need to login to post a comment.

I'm new to Snipplr and just posted this. I'm curious as to why it didn't preserve indentation? Did I do something wrong?
Sorry, I copied and pasted it from my blog and Firefox seems to remove indentation when copying for some strange reason.
Ok I didn't like this at all when I first looked at it but it honestly is the image captcha I have found and not to mention simple. Take the above code and place it in it's own file lets say captcha.php. On the form that you want to use it on just link to it like and make sure you add sessionstart(); to the above file and the form page. Also I would add the $SESSION['captcha_key'] = $key; under the $key variable and that is about it.
Znupi, sorry about the email figured I would post this so you didn't have to :)