REGISTER or LOGIN to have the annoying ads removed.
Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
basic CAPTCHA Image
05-17-2009, 07:27 PM
Post: #1
basic CAPTCHA Image
Well I was making a site and had to create some sort of CAPTCHA,

PHP Code:
<?php
session_start
();
mt_srand(time());
$my_img imagecreate20040 );
$bg imagecolorallocate($my_img000);
$blue  imagecolorallocate($my_img,   0,   0255);
$gray  imagecolorallocate($my_img169169169);
$wild  imagecolorallocate($my_imgmt_rand(1,255), mt_rand(1,255), mt_rand(1,255));
imagesetthickness $my_img);
imageline$my_img304516510$gray );
imageline$my_img35151221$blue );
$str substr(md5(microtime()*mktime()),0,mt_rand(5,7));
$_SESSION['captcha'] = $str;
imagestring$my_img4mt_rand(20,30), mt_rand(15,25), $str$wild );
header"Content-type: image/png" );
imagepng$my_img );
imagedestroy$my_img );
?>

Seems to work decently, It generates a very random string, that is 5 to 7 characters long

PHP Code:
$str substr(md5(microtime()*mktime()),0,mt_rand(5,7)); 

And uses a random color aswell as a somewhat random posistion, and throws 2 lines through the image then the captcha string is stored in $_SESSION['captcha']
Find all posts by this user
Quote this message in a reply
05-18-2009, 02:35 PM
Post: #2
RE: basic CAPTCHA Image
Pretty neat. Thanks for sharing the code.

Find all posts by this user
Quote this message in a reply
05-18-2009, 08:50 PM
Post: #3
RE: basic CAPTCHA Image
Very nice, this would be useful for login form, email forms, etc. Wink
Find all posts by this user
Quote this message in a reply
05-19-2009, 11:55 AM
Post: #4
RE: basic CAPTCHA Image
Thanks for sharing. I hope to make a website in future. Hopefully it helps. Smile
Find all posts by this user
Quote this message in a reply
06-21-2009, 07:50 AM
Post: #5
RE: basic CAPTCHA Image
Thanks for sharing the code, might use this for a registration form I might create, once again thanks.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: