Jump to content

PHP Captchas


limitphp

Recommended Posts

Here's one I wrote:

<?php
  session_start();
  $imgWidth=130;
  $imgHeight=34;
  $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
  $strText='';
  for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);}
  $_SESSION['vercode']=md5($strText);
  header("Content-type: image/png");
  $img=imagecreatetruecolor($imgWidth,$imgHeight); //enable if plain colored background is to be used
  //$img=imagecreatefrompng('gfx/codebg.png'); //enable if patterned background image is to be used
  $colBG=imagecolorallocate($img,0x11,0x11,0x11);
  for ($i=0;$i<strlen($strText);$i++) {
    $colFG=imagecolorallocate($img,mt_rand(50,255),mt_rand(50,255),mt_rand(50,255));
    imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1));
  }
  imagepng($img);
  imagedestroy($img);
?>

 

Just make sure your TFF font is in the same place as specified by the imagettftext line.

 

Just MD5 the input from your user and check it with $_SESSION['vercode']

 

Call with:

<img src="makeimg.php?<?=mt_rand(1,100000)?>" />

Link to comment
https://forums.phpfreaks.com/topic/131693-php-captchas/page/2/#findComment-722312
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.