Проверка для captcha

Добавил капчу при регистрации. Никак не могу понять, как добавляется проверка ее ввода.

captcha.php

<?php

session_start();

$strings = '123456789';
$i = 0;
$characters = 4;
$code = '';
while ($i < $characters)
{ 
    $code .= substr($strings, mt_rand(0, strlen($strings)-1), 1);
    $i++;
} 

$_SESSION['captcha'] = $code;

//generate image
$im = imagecreatetruecolor(124, 40);
$foreground = imagecolorallocate($im, 0, 0, 0);
$shadow = imagecolorallocate($im, 173, 172, 168);
$background = imagecolorallocate($im, 255, 255, 255);

imagefilledrectangle($im, 0, 0, 200, 200, $background);

// use your own font!
$font = '/var/www/myshop33.ru/fonts/Comic_Sans_MS.ttf';

//draw text:
imagettftext($im, 35, 0, 9, 28, $shadow, $font, $code);
imagettftext($im, 35, 0, 2, 32, $foreground, $font, $code);     

// prevent client side  caching
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//send image to browser
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);

?>

rigistration.php

<?php
    $title = "Регистрация";
    require_once "./template/header.php";
?>

    <form class="form-horizontal" method="post" action="user_signup.php">
    <div class="form-group">
        <label for="exampleInputEmail1">Имя</label>
        <input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Имя" name="firstname">
    </div>
    <div class="form-group">
        <label for="exampleInputEmail1">Фамилия</label>
        <input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Фамилия" name="lastname">
    </div>
    <div class="form-group">

        <label for="inputEmail4">Email</label>
        <input type="text" class="form-control" id="inputEmail4" placeholder="Email" name="email">
        </div>
        <div class="form-group">
        <label for="inputPassword4">Пароль</label>
        <input type="password" class="form-control" id="inputPassword4" placeholder="Пароль" name="password">
    </div>
    <div class="form-group">
        <label for="inputAddress">Адрес</label>
        <input type="text" class="form-control" id="inputAddress" placeholder="Адрес" name="address">
    </div>
    <div class="form-row">
        <div class="form-group col-md-4">
        <label for="inputCity">Город</label>
        <input type="text" class="form-control" id="inputCity" name="city">



//ЗДЕСЬ ФОРМА ДЛЯ ВВОДА И КАПЧИ
<img src="captcha.php">
Enter the code above: <input type="text" name="captcha">




        </div>
        <div class="form-group col-md-2">
        </div>
        <div class="form-group col-md-4">
        <label for="inputZip">Номер телефона</label>
        <input type="text" class="form-control" id="inputZip" name="zipcode">
        </div>
    </div>

    <div class="form-group col-md-12">
    <button type="submit" class="btn btn-danger">Продолжить</button>
    </div>
</form>
<div style="position:fixed; bottom:120px">

<?php

    $fullurl="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    if(strpos($fullurl,"signup=empty")==true){
        echo '<P style="color:red">Вы не заполнили все поля</P>';
        exit();
    }
    if(strpos($fullurl,"signup=invalidemail")==true){
        echo '<P style="color:red">Такого email не существует</P>';
        exit();
    }
?>
</div>
<?php


    require_once "./template/footer.php";

?>

Дальше нужно добавить условие, но куда его добавить, не совсем понимаю. Оно должно находиться в этом же файле rigistration.php?

if ($_POST['captcha'] == $_SESSION['captcha'])
    // do your thing

Ответы (0 шт):