<?php

if (preg_match('/captcha.php/i', $_SERVER['PHP_SELF']))
{ header("location: 404_not_found.php");
  exit;
  }
  
$font_path="common/include/captcha/font";
$fontfile=$font_path."/tahoma.ttf";

$_SESSION['new_string']="";
$_SESSION['the_string']="";

srand((double)microtime()*1000000); 
$string=md5(rand(0, 9999)); 

$_SESSION['new_string']=strtoupper(substr($string, 17, 5));
$_SESSION['the_string']=$string;

$angle=rand(0, 5);
$size=rand(12, 14);
$coords=imagettfbbox($size, $angle, $fontfile, $_SESSION['new_string']);

$width=abs($coords[4]-$coords[0])+75;
$height=abs($coords[5]-$coords[1])+30;
$gambar=ImageCreate($width, $height); 

$bg_color=imagecolorallocate($gambar,rand(192,255),rand(192,255),rand(192,255));
$textcolor=imagecolorallocate($gambar,rand(0,128),rand(0,128),rand(0,128));

ImageFill($gambar, 0, 0, $textcolor);
Imagettftext($gambar, $size, $angle, $size, $size*2, $bg_color, $fontfile, $_SESSION['new_string']);

ImagePNG($gambar, "ver_code/verify".$string.".png");
ImageDestroy($gambar); 

?>