Captcha plugin for php

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.

License

Gregwar/Captcha

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

Captchas examples

You can create a captcha with the CaptchaBuilder :

 use Gregwar\Captcha\CaptchaBuilder; $builder = new CaptchaBuilder; $builder->build();

You can then save it to a file :

 header('Content-type: image/jpeg'); $builder->output();

Or inline it directly in the HTML page:

 $builder->inline(); ?>" />

You’ll be able to get the code and compare it with a user input :

 // Example: storing the phrase in the session to test for the user // input later $_SESSION['phrase'] = $builder->getPhrase();

You can compare the phrase with user input:

if($builder->testPhrase($userInput)) < // instructions if user phrase is good > else < // user phrase is wrong >

You can use theses functions :

  • __construct($phrase = null), constructs the builder with the given phrase, if the phrase is null, a random one will be generated
  • getPhrase(), allow you to get the phrase contents
  • setDistortion($distortion), enable or disable the distortion, call it before build()
  • isOCRReadable(), returns true if the OCR can be read using the ocrad software, you’ll need to have shell_exec enabled, imagemagick and ocrad installed
  • buildAgainstOCR($width = 150, $height = 40, $font = null), builds a code until it is not readable by ocrad
  • build($width = 150, $height = 40, $font = null), builds a code with the given $width, $height and $font. By default, a random font will be used from the library
  • save($filename, $quality = 80), saves the captcha into a jpeg in the $filename, with the given quality
  • get($quality = 80), returns the jpeg data
  • output($quality = 80), directly outputs the jpeg code to a browser
  • setBackgroundColor($r, $g, $b), sets the background color to force it (this will disable many effects and is not recommended)
  • setBackgroundImages(array($imagepath1, $imagePath2)), Sets custom background images to be used as captcha background. It is recommended to disable image effects when passing custom images for background (ignore_all_effects). A random image is selected from the list passed, the full paths to the image files must be passed.
  • setInterpolation($interpolate), enable or disable the interpolation (enabled by default), disabling it will be quicker but the images will look uglier
  • setIgnoreAllEffects($ignoreAllEffects), disable all effects on the captcha image. Recommended to use when passing custom background images for the captcha.
  • testPhrase($phrase), returns true if the given phrase is good
  • setMaxBehindLines($lines), sets the maximum number of lines behind the code
  • setMaxFrontLines($lines), sets the maximum number of lines on the front of the code

If you want to change the number of character, you can call the phrase builder directly using extra parameters:

use Gregwar\Captcha\CaptchaBuilder; use Gregwar\Captcha\PhraseBuilder; // Will build phrases of 3 characters $phraseBuilder = new PhraseBuilder(4); // Will build phrases of 5 characters, only digits $phraseBuilder = new PhraseBuilder(5, '0123456789'); // Pass it as first argument of CaptchaBuilder, passing it the phrase // builder $captcha = new CaptchaBuilder(null, $phraseBuilder);

You can also pass directly the wanted phrase to the builder:

// Building a Captcha with the "hello" phrase $captcha = new CaptchaBuilder('hello');

If you want to see an example you can have a look at the demo/form.php , which uses demo/session.php to render a captcha and check it after the submission

You can have a look at the following repository to enjoy the Symfony 2 bundle packaging this captcha generator : https://github.com/Gregwar/CaptchaBundle

You can use the following extension for integrating with Yii2 Framework : https://github.com/juliardi/yii2-captcha

This library is under MIT license, have a look to the LICENSE file

Источник

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.

PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

License

google/recaptcha

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

Initial default GitHub Actions configuration for PHP

Git stats

Files

Failed to load latest commit information.

README.md

reCAPTCHA PHP client library

reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the server-side verification step required to process responses from the reCAPTCHA service. This client supports both v2 and v3.

  • reCAPTCHA: https://www.google.com/recaptcha
  • This repo: https://github.com/google/recaptcha
  • Hosted demo: https://recaptcha-demo.appspot.com/
  • Version: 1.3.0
  • License: BSD, see LICENSE

Use Composer to install this library from Packagist: google/recaptcha

Run the following command from your project directory to add the dependency:

composer require google/recaptcha "^1.3"

Alternatively, add the dependency directly to your composer.json file:

"require": < "google/recaptcha": "^1.3" >

Support for earlier versions of PHP

The 1.3 release moves to PHP 8 and up. For earlier versions, you will need to stay with the 1.2 releases.

Download the ZIP file and extract into your project. An autoloader script is provided in src/autoload.php which you can require into your script. For example:

require_once '/path/to/recaptcha/src/autoload.php'; $recaptcha = new \ReCaptcha\ReCaptcha($secret);

The classes in the project are structured according to the PSR-4 standard, so you can also use your own autoloader or require the needed files directly in your code.

First obtain the appropriate keys for the type of reCAPTCHA you wish to integrate for v2 at https://www.google.com/recaptcha/admin or v3 at https://g.co/recaptcha/v3.

Then follow the integration guide on the developer site to add the reCAPTCHA functionality into your frontend.

This library comes in when you need to verify the user’s response. On the PHP side you need the response from the reCAPTCHA service and secret key from your credentials. Instantiate the ReCaptcha class with your secret key, specify any additional validation rules, and then call verify() with the reCAPTCHA response (usually in $_POST[‘g-recaptcha-response’] or the response from grecaptcha.execute() in JS which is in $gRecaptchaResponse in the example) and user’s IP address. For example:

 $recaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com') ->verify($gRecaptchaResponse, $remoteIp); if ($resp->isSuccess()) < // Verified! > else < $errors = $resp->getErrorCodes(); >

The following methods are available:

  • setExpectedHostname($hostname) : ensures the hostname matches. You must do this if you have disabled «Domain/Package Name Validation» for your credentials.
  • setExpectedApkPackageName($apkPackageName) : if you’re verifying a response from an Android app. Again, you must do this if you have disabled «Domain/Package Name Validation» for your credentials.
  • setExpectedAction($action) : ensures the action matches for the v3 API.
  • setScoreThreshold($threshold) : set a score threshold for responses from the v3 API
  • setChallengeTimeout($timeoutSeconds) : set a timeout between the user passing the reCAPTCHA and your server processing it.

Each of the set * () methods return the ReCaptcha instance so you can chain them together. For example:

 $recaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com') ->setExpectedAction('homepage') ->setScoreThreshold(0.5) ->verify($gRecaptchaResponse, $remoteIp); if ($resp->isSuccess()) < // Verified! > else < $errors = $resp->getErrorCodes(); >

You can find the constants for the libraries error codes in the ReCaptcha class constants, e.g. ReCaptcha::E_HOSTNAME_MISMATCH

For more details on usage and structure, see ARCHITECTURE.

You can see examples of each reCAPTCHA type in examples/. You can run the examples locally by using the Composer script:

composer run-script serve-examples

This makes use of the in-built PHP dev server to host the examples at http://localhost:8080/

These are also hosted on Google AppEngine Flexible environment at https://recaptcha-demo.appspot.com/. This is configured by app.yaml which you can also use to deploy to your own AppEngine project.

No one ever has enough engineers, so we’re very happy to accept contributions via Pull Requests. For details, see CONTRIBUTING

About

PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

Источник

Читайте также:  Тигровый питон сколько живут
Оцените статью