View file code.php

File size: 1.02Kb
<?php
session_start();

$_SESSION['code'] = rand(1000, 9999);

$img = imagecreate(42, 18);

imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));

ImageString($img, 5, rand(2, 3), rand(0, 3), substr($_SESSION['code'], 0, 1), imagecolorallocate($img, rand(0, 204), rand(0, 204), rand(0, 204)));
ImageString($img, 5, rand(11, 12), rand(0, 3), substr($_SESSION['code'], 1, 1), imagecolorallocate($img, rand(0, 204), rand(0, 204), rand(0, 204)));
ImageString($img, 5, rand(20, 21), rand(0, 3), substr($_SESSION['code'], 2, 1), imagecolorallocate($img, rand(0, 204), rand(0, 204), rand(0, 204)));
ImageString($img, 5, rand(29, 30), rand(0, 3), substr($_SESSION['code'], 3, 1), imagecolorallocate($img, rand(0, 204), rand(0, 204), rand(0, 204)));

for ($i = 0; $i <= 5; $i++) {
	$pos = array(rand(0, 42), rand(0, 18), rand(0, 42), rand(0, 18));
	imageline($img, $pos[0], $pos[1], $pos[2], $pos[3], imagecolorallocate($img, 204, 204, 204));
}

header("Content-type: image/gif");

ImageGIF($img);

ImageDestroy($img);
?>