Download the PHP package mmdm/sim-captcha without Composer

On this page you can find all versions of the php package mmdm/sim-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sim-captcha

Simplicity Captcha

A library for captcha.

Install

composer

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

and you are good to go.

How to use

Available functions

There are two captcha generator for now.

You can get a new instance from specific class like this

The language specified above is to generate a captcha with your locale language words and numbers.

If you want to add a language for your locale you can implement ICaptchaLanguage interface. It has three functions you should implement.

For convenience there is a CaptchaFactory class that creates captcha you want. Just call instance method statically.

If you need to type hint your variable, according to your IDE you should type hint variable. Most of editors should work with @var.

instance(int $type = CaptchaFactory::CAPTCHA, ICaptchaLanguage $language = null)

As you can see there is a type variable that you can specify which class you need to instantiate. Under CaptchaFactory constants there are CaptchaFactory::CAPTCHA and CaptchaFactory::CAPTCHA_SIMPLE_MATH for class instantiating.

Second parameter is language of captcha. If you don't specify that, it'll be English by default.

Note: Please use constants, because if numbers changed in future, you will have problem and have to refactoring captcha instantiating.

Note: For now there are three languages: [English, Persian, Arabic].

Important Note Generate captcha codes in any languages are from Left to Right. Please inform user from this behavior if you have rtl language alphabet.

Common Methods

generate()

This method will generate captcha

verify($input)

This method is to verify generated captcha by sending user's value.

setName(string $name = null)

With this method you can store captcha under a name you specify. For example if you want to have captcha in several pages and user want to use multiple pages that have captcha, those generated captcha will mixed up and just one page can submit and others will say captcha is not valid! To solve this problem you should specify a name for generated captcha to prevent that.

Default name is captcha

getName()

This method returns captcha name.

setExpiration(int $expire_time)

You can specify expiration of captcha with this method

Default expiration is 600s

Note: pass time as seconds

getExpiration()

This method returns expiration time of captcha in seconds

Common Methods in Text Captcha

It has all methods of Common Methods and below methods.

generateBase64Code(string $code = null)

This method returns base64 image code only.

setWidth(int $width)

This method sets the captcha image width

Default is 200.

getWidth(): int

This method returns captcha image width.

setHeight(int $height)

This method sets the captcha image height

Default is 50.

getHeight(): int

This method returns captcha image height.

setFont(string $filename)

You can specify the font of captcha. Just send font's filename as parameter. By default there are three fonts with this library:

These fonts' filename have constant under CaptchaFactory class: CaptchaFactory::FONT_MENLO, CaptchaFactory::FONT_LATEEF and CaptchaFactory::FONT_IRAN_SANS

or if you have other fonts to use, just send filename as parameter.

getFont()

This method returns font's filename string

setFontSize(int $size)

You can specify size of captcha's font.

Default is 20.

getFontSize(): int

This method returns captcha's font size

setImgAttributes(array $attributes)

Because of generate method result, that is an image(for captcha text), setting attributes is a problem. With this method you can set attribute of captcha image.

getImgAttributes(): array

This method returns captcha image attributes as array

getImgAttributesString(): string

This method returns captcha image attributes as string

addNoise(bool $answer)

If you need to have noise on captcha, send true as parameter to this method.

Default is true

useEnglishNumbersToVerify(bool $answer)

If your user enter the captcha characters as input, it may be valid but not valid! It is because the user enter numbers in another language than locale. Like arabic numbers that user enter them as english, they may be equal but different in the same time. You can prevent that with sending true as parameter to this method and it'll convert all numbers from specified language to english and then verify entered code.

Default is false

Note: Use this method before verify method.

Note: Be careful and specify language before verify method to prevent unwanted behaviors.

Captcha

It has all methods of Common Methods in Text Captcha and below methods.

generate(string $code = null)

This method generates a captcha code. Also you can set your own code to generate as captcha.

setLength(int $length): Captcha

With this method you can set length of generated captcha

Default is 6.

getLength(): int

Get length of captcha characters that used in code generation

setDifficulty(int $difficulty): Captcha

There is three difficulty for captcha codes [easy, medium, hard] that can pass to this method using constants under CaptchaFactory:

  1. CaptchaFactory::DIFFICULTY_EASY
  2. CaptchaFactory::DIFFICULTY_NORMAL
  3. CaptchaFactory::DIFFICULTY_HARD

Easy makes captcha code to be just numbers.

Normal makes captcha code to be numbers and capital characters.

Hard makes captcha code to be numbers, capital characters and small characters.

Default is CaptchaFactory::DIFFICULTY_NORMAL

Note: All numbers and alphabet used from specified language

Note: Because CaptchaFactory::DIFFICULTY_NORMAL use capital characters, it is CASE-INSENSITIVE.

getDifficulty(): int

Get captcha difficulty

CaptchaSimpleMath

It has all methods of Common Methods in Text Captcha and below methods.

setNumbersCount(int $count): CaptchaSimpleMath

You can specify how many numbers should participate in. It should be a number between 2 and 5(inclusive).

Default is 2.

getNumbersCount(): int

This method returns numbers of participated numbers in captcha.

useMultiplyOperands(): CaptchaSimpleMath

By default the operands for math are [+, -] and if you need multiplication, just call this method before captcha generation.

How to generate captcha multiple times in a page

Because of page caching, you can not generate captcha with the captcha object in one request, therefore you should use ajax.

In tests folder you can see an example of this usage. The captcha will generate by ajax from beginning.

index.php is the base page for it and captcha.php is the page that gives captcha each time.

See script part of index.php if you are not familiar with ajax creation or not using a library like jQuery to create ajax request.

Note: If you store captcha under a specific name, be careful and send name of captcha with ajax request.

License

Under MIT license.


All versions of sim-captcha with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-gd Version *
ext-mbstring Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mmdm/sim-captcha contains the following files

Loading the files please wait ....