Custom Search

Sunday, May 18, 2008

How to : Image Validator In PHP

This simple source to create image validator function :

function generate_image_validator(){
global $app;
// Create an image where width=155 pixels and height=35 pixels
$val_img = imagecreate(155, 35);
// Allocate 2 colors to the image
$color1 = imagecolorallocate($val_img, 46,60,31);
$color2 = imagecolorallocate($val_img, 238,239,239);
// Create a seed to generate a random number
srand((double)microtime()*1000000);
// Run the random number seed through the MD5 function
$seed_string = md5(rand(0,9999));
// Chop the random string down to 5 characters
// This is the validation code we will use
$val_string = substr($seed_string, 17, 5);
// Set the background of the image to color2
imagefill($val_img, 0, 0, $color2);
// Print the validation code on the image in color1
imagestring($val_img, 4, 75, 10, $val_string, $color1);
// Write the image file to the current directory
imagejpeg($val_img, "img.jpg");
imagedestroy($val_img);
$app[val_string]=$val_string;
return;
}





No comments:

Free Traffic

 Join My Community at MyBloglog! Blog Flux Directory 

Web Developement Blogs - BlogCatalog Blog Directory web development blog  Internet Blogs - Blog Top Sites 

Blog Directory 

Click Here for Free Traffic!

Link2Communion.com