Boolean Island !

Image Validation Script

Posted by: ranacse05 on: April 11, 2008

When ever we try to get register ourselves in any web app we have to pass the image validation.Its for the security.This can be done in 2 ways

  • Using Database
  • Generate the Image Dynamically

If we follow the first one the we have to have a database where we’ll store the image.And we have to generate lots of image manually and stored there.Sounds bad to me :( .

I was just working on a new project.There i have to use an image validation.So i wrote a library which will generate the image dynamically,so i dont have to worry about generate a lots of image and store them on database.Here is the code

<?php
function security_image($rand) {
$width = 100;
$height = 25;
$image = imagecreate($width, $height);
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, 255, 0, 0);

// Add Random noise
for ($i = 0; $i < 10; $i++) {
$rx1 = rand(0,$width);
$rx2 = rand(0,$width);
$ry1 = rand(0,$height);
$ry2 = rand(0,$height);
$rcVal = rand(0,255);
$rc1 = imagecolorallocate($image,
rand(0,255),
rand(0,255),
rand(100,255));

imageline ($image, $rx1, $ry1, $rx2, $ry2, $rc1);
}

imagestring($image, 5, 30, 10, $rand, $textColor);

@header(‘Content-type: image/png’);
imagepng($image,”s.png”);
imagedestroy($image);
}
?>

Now call the function

$new = //your string u wanna show as image
security_image($new);

Then use img tag to view the s.png file where u want. :)

4 Responses to "Image Validation Script"

Nice work. I’m also trying this with the help of Net. thnx for faster help.

ok I will try this. thanks

cool ….. sounds really gr8 ….good job!

Leave a Reply

My blog worth


My site is worth $3431.
How much is yours worth?

My Twittes

FireFox

Firefox 3

My Facebook

this is Raquibul's profile

View Raquibul Islam's profile on LinkedIn

My fav

 

April 2008
S M T W T F S
« Mar   May »
 12345
6789101112
13141516171819
20212223242526
27282930  

Flickr Photos

Moon !

Moon !

Leevio

Leevio

Leevio

Tea !

History

me

More Photos

My Bookmarks

Dynamic Malloc

Blog Stats

  • 46,705 hits