Просмотр поста

.
MyZik
Bewahret einander vor Herzeleid

Доброго времени суток. Прошу помочь с внедрением системы каптчи на свой ресурс.
Код каптчи:

<?php
session_start(); 
$string = "";
for ($i = 0; $i < 5; $i++)
$string .= chr(rand(97, 122));

$_SESSION['rand_code'] = $string;

$dir = "fonts/";

$image = imagecreatetruecolor(170, 60);
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 205, 100, 49);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image,0,0,399,99,$white);
imagettftext ($image, 30, 0, 10, 40, $color, $dir."advert.ttf", $_SESSION['rand_code']);

header("Content-type: image/png");
imagepng($image);
?>

Проверка на правильность
$code = txt($_POST['code']);
  if ($code != $_SESSION['rand_code'])
    $err[] = $lang['captcha_error'];

Ну, и собсно, вывод
echo '<img src="' . URL . '/utils/captcha.php" width="100" height="30" alt="CAPTCHA" /><br />' .
  '<input type="text" name="code" size="5" maxlength="5" /><br />';

Проблема в том, что каптча показывается, но ввод всегда считается неверным