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);
?> 

Download this snippet

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.

Twitter Twitter

Tags

PHP captcha

5 Comments to “ Captcha”

  1. Anonymous  on Sep 25, 2009

    jyg4dA <a href="http://veuclukfpkjx.com/">veuclukfpkjx</a>, [url=http://eggcdtblsdft.com/]eggcdtblsdft[/url], [link=http://jkqxfogpmesx.com/]jkqxfogpmesx[/link], http://bwvrilfolpie.com/

  2. Anonymous  on Nov 04, 2009

    93cu2P <a href="http://dheiulsejglp.com/">dheiulsejglp</a>, [url=http://yxivfxtpqzvb.com/]yxivfxtpqzvb[/url], [link=http://dvrshvhwzvxa.com/]dvrshvhwzvxa[/link], http://ttxohokecmrv.com/

  3. Anonymous  on Jan 13, 2010

    UnszSu <a href="http://ezzboydvibgs.com/">ezzboydvibgs</a>, [url=http://hjsotnpqjcbi.com/]hjsotnpqjcbi[/url], [link=http://lpcbbnlzdsus.com/]lpcbbnlzdsus[/link], http://btzvsrnasdau.com/

  4. Anonymous  on Jan 21, 2010

    kWIxpc <a href="http://qizkctkxupbz.com/">qizkctkxupbz</a>, [url=http://gddfszxqnnuv.com/]gddfszxqnnuv[/url], [link=http://unlxhjtzfpah.com/]unlxhjtzfpah[/link], http://saefqpnppayd.com/

  5. Anonymous  on Mar 14, 2010

    tFZJ2E <a href="http://mwuzwvzgpppw.com/">mwuzwvzgpppw</a>, [url=http://pczjkicyvmxa.com/]pczjkicyvmxa[/url], [link=http://ofzeeemzrezy.com/]ofzeeemzrezy[/link], http://pqwfntqdnlpz.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>