Username:   Password:  

Captcha

<?php
	function make_seed(){
		list($usec , $sec) = explode (' ', microtime());
		return (float) $sec + ((float) $usec * 100000);
	}
 
	function randomString($len) {	
		srand(make_seed());
 
		$possible = 'abcdefhijkmnprstuvwxyz23456789';
 
		$str = '';
		while(strlen($str)<$len) {
			$str .= substr($possible,(rand()%(strlen($possible))),1);
		}
 
		return($str);
	}
 
	session_start();
 
	unset($_SESSION['captcha_spam']);
 
	$text = randomString(5);
	$_SESSION['captcha_spam'] = $text;
 
	header('Content-type: image/png');
	$img = ImageCreateFromPNG('captcha.png');
	$color = ImageColorAllocate($img, 0, 0, 0);
	$ttf = getcwd().'/somefont.tff';
	$ttfsize = 20;
	$angle = rand(0,5);
	$t_x = rand(5,20);
	$t_y = 25;
	imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
	imagepng($img);
	imagedestroy($img);
?> 

Simple captcha image. captcha.png is the backround image for you captcha. "somefont.tff" is a random truetype font for the text in your captcha image.

Tags

PHP captcha