PHP

Пример captcha на php

CAPTCHA: “Computer Aided Public Turing test to tell Computers and Humans Apart

Код вывода изображения(captcha.php):
<?php
session_start();
header("Content-Type: image/jpeg");
get_checkcode_picture(substr(session_id(),-4,4));
die;

function get_checkcode_picture($code){
    $img=imagecreatetruecolor(50, 30);
    $x1=0;
    $x2=60;
    $y1=rand(0, 30);
    $y2=rand(00, 30);
    $textcolor = imagecolorallocate ( $img , 255, 255, 255);
    imageline($img, $x1, $y1, $x2, $y2, $textcolor);
    $x1=rand(0, 50);
    $x2=rand(0, 50);
    $y1=0;
    $y2=30;
    imageline($img, $x1, $y1, $x2, $y2, $textcolor);
    imagestring($img, 4, 10, 7, $code, $textcolor);
    imagejpeg($img);
}
?>

Код запроса:
Cимволы с картинки:<br />
<img src=\"captcha.php\" width=50 height=30>
<input name=\"captcha\" size=5 type=\"text\" />

Код проверки:
<?php
if (@$_POST['captcha'])!=substr(session_id(),-4,4))
   die('Символы на картинке введены неверно!');
?>

Если подойти с творческим подходом, можно встроить такую captcha в форму отправки письма на e-mail с сайта. Напоминаю здесь только приведен код, который будет выводить примерно такую captcha.
Теги:
captcha
Добавлено: 29 Мая 2018 17:52:27 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...