<?php
session_start();

// Generate random code
$captcha_code = rand(1000, 9999);
$_SESSION['captcha'] = $captcha_code;

// Create image
$image = imagecreate(70, 30);
$bg = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);

// Add text to image
imagestring($image, 5, 10, 8, $captcha_code, $text_color);

// Output image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
