<?php
session_start();

$code = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 6);
$_SESSION['captcha_code'] = $code;

$img = imagecreatetruecolor(100, 38);
$bg = imagecolorallocate($img, 22, 86, 165); // Background color
$fg = imagecolorallocate($img, 255, 255, 255); // Text color
imagefill($img, 0, 0, $bg);
imagestring($img, 5, 10, 10, $code, $fg);

header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>