function CaptchaImg(){
$image = imagecreatetruecolor(200, 50);
$background_color = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image,0,0,200,50,$background_color);
$line_color = imagecolorallocate($image, 255,255,255);
$number_of_lines=rand(3,7);
for($i=0;$i<$number_of_lines;$i++)
{
imageline($image,0,rand()%50,250,rand()%50,$line_color);
}
$pixel = imagecolorallocate($image, 0,0,255);
for($i=0;$i<500;$i++)
{
imagesetpixel($image,rand()%200,rand()%50,$pixel);
}
$allowed_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$length = strlen($allowed_letters);
$letter = $allowed_letters[rand(0, $length-1)];
$word='';
$text_color = imagecolorallocate($image, 0,0,0);
$cap_length=6;// No. of character in image
for ($i = 0; $i< $cap_length;$i++)
{
$letter = $allowed_letters[rand(0, $length-1)];
imagestring($image, 5, 5+($i*30), 20, $letter, $text_color);
$word.=$letter;
}
$_SESSION['Captcha'] = $word;
$RandName=rand(1000000,9999999999);
imagepng($image, "Captcha$RandName.png");
$Result= '<img src="'.$GLOBALS['Domain'].'/Captcha'.$RandName.'.png" class="img-fluid d-block mb-2">';
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if(FindInValue($entry,"Captcha")==True AND $entry!="Captcha$RandName.png"){
unlink($entry);
}
}
}
closedir($handle);
}
return $Result;
}