Skip to content

lgbSalzburg/PHPCaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPCaptcha

wakatime

PHPCaptcha is a PHP library for easy Implementations of captchas.

A captcha is a completely automated public Turing test to tell computers and humans apart.

Place on website

To place the captcha on your website you need to do the following steps:

  1. Import PHPCaptcha.php into the namespace (this has to be before initiating the object)
include 'PHPCapcha.php';

  1. Create a PHPCaptcha object with the path to the folder where the captcha images are stored as argument
$captcha = new PHPCaptcha('img/');

  1. (Set the width of the image in px)
$captcha->setWidth(200);

This is only necessary if you want to change the with of the image which is set to 300px by default.


  1. Add the verify() function to your existing code
$error = !$captcha->verify($_POST['input'], $_POST['hash']);

  1. Add/Remove the verify button of the captcha:

Normaly the captcha is used below an input form, so there should already be a button to send of the form.

If you still want to display the verify button add this line:

$captcha->displayButton(true);

with this button you can just use this code to verify the input:

if(isset($_POST['verify'])){
	if($captcha->verify($_POST['input'], $_POST['hash']))
		echo "true";
	else
		echo "false";
}

  1. To display the captcha use the show() function in the place you want it to be displayed
$captcha->show();

Styles

There is a stylesheet which only contains some basic styles. Feel free to add your own styles in there :)

Generate Images

To generate the images, just run create.py with the number of images you want to generate as argument.

(If you have not added the python lib Pillow just run install.py or get it from the official page.)

These images will be saved in the img/ folder in the same directory as the py folder. The file name of the images is the text displayed on them hashed with sha256

Sample Images

If you do not want to generate your own images, there are 50 sample images in the img folder for you to use.

Requirements

Just for the Captcha you only need PHP 8.0 running

If you want to generate your own captcha images you also need python 3.4 or higher Additionaly you need pip in order to install Pillow

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published