Простенький код капчи, числовой
<?php
// Тrial...
session_start();
if(empty($_POST)) {
$num1 = rand(0,9);
$num2 = rand(0,9);
$num3 = rand(0,9);
$num4 = rand(0,9);
$num = "$num1$num2$num3$num4";
$_SESSION['num'] = $num;
echo $_SESSION['num'];
echo '<form action="index.php?num" method="post">
<input type="text" name="code"><input type="submit" value="Ввести"></form>';
} elseif(isset($_GET['num'])) {
$code = $_SESSION['num'];
$num = $_POST['code'];
if($code == $num) {
echo 'верно';
} else {
echo 'не верно';}}
?>