- Saved searches
- Use saved searches to filter your results more quickly
- License
- pstimpel/phpcaptcha
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- readme.md
- About
- Создание простой капчи на PHP
- Исходные коды капчи
- Верстка формы
- Генерация кода капчи и изображения
- Скрипт для обновления капчи на форме
- Написание обработчика формы
- JavaScript для отправки формы на сервер через AJAX
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Simple php server based captcha using GD
License
pstimpel/phpcaptcha
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
readme.md
Since Google and others are abusing Captchas to be tracking utilities, it was time to write a server based Captcha. Since the data are processed on your webserver only, this Captcha is GDPR safe. PHP Captcha does not forward any data away from your server. You do not need to mention it in your privacy policy. But of course I would like it very much, if you could add a reference to this project.
PHP Captcha is available under the terms of GPLv3. See License for more information.
PHP Captcha is using GD to generate images. PHP5 and PHP7 are supported.
- Download the latest release here: https://github.com/pstimpel/phpcaptcha/releases
- Unpack the content of the zip into a folder on your webserver, let’s say to modules in your webroot
- Use your webbrowser and browse to /modules/phpcaptcha-/index.php
- If 3. works fine, you could configure PHP Captcha by editing /modules/phpcaptcha-/config.php
_Do not attempt a change of your configuration until you finished step 3 of the installation with success! _
stringLength: How many characters to use for the captcha, default is 6
charsToUse Which characters to choose from, default is abcdefghkmnprstuvwxyz23456789 , it might be a good idea to skip characters like I and 1 for avoiding confusion
strictLowerCase: Limit captcha to lower case, default is true , if there are no upper case characters in your charsToUse , this option is useless
bgcolor.r: Red value of background color, default is 0, valid from 0 to 255
bgcolor.g: Green value of background color, default is 0, valid from 0 to 255
bgcolor.b: Blue value of background color, default is 0, valid from 0 to 255
textcolor.r: Red value of text color, default is 255, valid from 0 to 255
textcolor.g: Green value of text color, default is 255, valid from 0 to 255
textcolor.b: Blue value of text color, default is 255, valid from 0 to 255
font: Name of TTF font to use, default is ‘Lato-Regular.ttf’, but you can use any TTF font you like.
Font Lato is GPL, OFL and Public Domain by Łukasz Dziedzic, can be found at https://www.1001freefonts.com/lato.font
sessionName: The name of the session var PHP Captcha is using to store the text from the captcha, default is phpcaptcha , which is accessible in $_SESSION[‘phpcaptcha’]
size.width: The width of the generated image, default is 200
size.height: The height of the generated image, default is 50
fontsize: The font size to be used, default is 25
numberOfLines: The number of lines to draw across the image for creating some small confusion to OCR, default is 6
thicknessOfLines: The thickness per line, default is 2
linecolor.r: Red value of line color, default is 128, valid from 0 to 255
linecolor.g: Green value of line color, default is 128, valid from 0 to 255
linecolor.b: Blue value of line color, default is 128, valid from 0 to 255
There is a Demo available, if you unzipped the package at your webserver. Just navigate to the demo subfolder using your webbrowser. If GD is missing, PHP Captcha will detect it and throw an error. If you misconfigured PHP Captcha, it will try to run on defaults, or throw an error depending on the type of your failure.
If it was installed and configured well, just reference /modules/phpcaptcha/index.php as image in your html form.

You will have to add a textfield to your form as well, so the user can type in what he/she/it sees on the captcha image. Let’s do it like this:
Now, make a check where you evaluate the form data. A simple
if($_POST['captchatext'] == $_SESSION['phpcaptcha']) < //Captcha solution OK >else < //Captcha solution wrong >
will do. Of course you should run checks like isset() on both variables before.
However, you are ready to go, congrats!
About
Simple php server based captcha using GD
Создание простой капчи на PHP
Captcha (капча) – это некий тест, который человек решает очень легко, а робот – нет (научить компьютер решать его крайне сложно и затруднительно).
Другими словами, основная цель капчи – это определить кем является пользователь: человеком или роботом .
Используется Captcha на сайте для защиты от спама и повышенной нагрузки, которые создают роботы. Капчу можно очень часто встретить в формах регистрации, входа, отправки сообщений, при скачивании файлов и многих других местах.
В большинстве случаев капча отображается как некоторый искаженный или наложенный на фон текст, который посетителю сайта необходимо разобрать и ввести его в некоторое поле. Кроме текста на фоне используется и другие алгоритмы: найти среди множества картинок правильные, собрать пазл, переместить слайдер, нарисовать связь между несколькими картинками и т.д.
Исходные коды капчи
Исходные коды капчи расположены на GitHub: itchief/captcha.
Процесс разработки капчи представлен в виде следующих этапов:
- верстка формы;
- создания файла «captcha.php» для генерация кода капчи и изображения;
- написание обработчика для формы (файл «process-form.php»);
- написание JavaScript для отправки формы на сервер через AJAX и обработки ответа.
Верстка формы
Разработку Captcha начнём с создания формы. Для простоты форма будет состоять из капчи и кнопки отправить:
Форма успешно отправлена!