<?php
/*
*it generates a random string and ouputs as jpg image.
*it stores the genereated random string to validate before submitting
*we can assume this file as image and we can link like a generel image.
*Author:G mahesh chari (http://www.maheshchari.com)
*/
@session_start(); //session start if it already not started
$rand_str = md5(microtime());// md5 to generate the random string
$result_str = substr($rand_str,0,6);//trim 5 digit 
$new_image =imagecreatefromjpeg("images/captcha.JPG");//image create by existing image and as back ground 
$line_color = imagecolorallocate($new_image,233,239,239);//line color 
$text_color = imagecolorallocate($new_image, 255, 0, 0);//text color-white
imageline($new_image,1,1,40,40,$line_color);//create line 1 on image 
imageline($new_image,1,100,60,0,$line_color);//create line 2 on image 
imagestring($new_image, 10, 50, 5, $result_str, $text_color);// Draw a random string horizontally 
$_SESSION['captcha_key'] = $result_str;// carry the data through session
header("Content-type: image/jpeg");// out out the image 
imagejpeg($new_image);//Output image to browser 

?>
