File: /var/www/vhosts/onlinedev.com/httpdocs/captcha.php
<?php
session_start();
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
$im = imagecreatetruecolor(100, 23);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 25, $black);
//path to font - this is just an example you can use any font you like:
$font = dirname(__FILE__).'/font/karate/Karate.ttf';
// $font = '/font/karate/Karate.ttf';
$t1 = imagettftext($im, 17, 4, 22, 23, $grey, $font, $randomnr);
$t2= imagettftext($im, 17, 4, 15, 23, $white, $font, $randomnr);
//var_dump ($t1, $t2); exit;
//prevent caching on client side:
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>