Download the PHP package marwelln/recaptcha without Composer

On this page you can find all versions of the php package marwelln/recaptcha. 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 recaptcha

What is reCAPTCHA?

reCAPTCHA is a free service to protect your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.

This package gives you an easy validation in PHP for Google's new (december 2014) reCAPTCHA. It allows you to validate if you are a human or robot with just a simple mouse click. See this Youtube link for a brief look at how it works.

Installation

You can install this package by using Composer.

Laravel

If you're using Laravel, you need to 'Marwelln\Recaptcha\RecaptchaServiceProvider' to your providers array in config/app.php.

Recaptcha keys

To use reCAPTCHA, you need to have a site key and a secret key. Click here to setup a domain and get your keys.

The site key is using for the widget and the secret key is used to validate the response we get from Google.

Front-end usage

To display the reCAPTCHA widget, you first need to include their javascript file on your site. Put the following code at the bottom of your site.

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

After that, you need to add a div where you want to display the widget. The required attributes is class with a value of g-recaptcha and data-sitekey with a value of your site key. Don't have a key? Get one over here.

<div class="g-recaptcha" data-sitekey="your_site_key"></div>

There are three optional attributes available for you to style and manage the widget. It's data-theme, data-type and data-callback. See Google's configuration documentation for up-to-date and more details about each attribute.

Laravel

If your using Laravel, you can display the widget by including the available view file. This will include the script file and the div tag.

Laravel 5:

{!! View::make('recaptcha::display') !!}

Laravel 4:

{{ View::make('recaptcha::display') }}

Back-end usage

To validate the response we get from Google we use the Marwelln\Recaptcha\Model class.

$validator = new \Marwelln\Recaptcha\Model($_POST['g-recaptcha-response'], $secretKey);
$validated = $validator->validate();

$response = '';
if ( ! $validated) {
    $response .= '<pre>' . print_r($validator->errors(), true) . '</pre>';
}

$response .= 'Did I validate? ' . ($validated ? 'Yes.' : 'No.');

echo $response;

If you don't want to insert $secretKey everytime you want to validate the response, you can add an environment value with RECAPTCHA_SECRETKEY as key.

putenv('RECAPTCHA_SECRETKEY=my-recaptcha-secret-key');

$validator = new \Marwelln\Recaptcha\Model($_POST['g-recaptcha-response']);

Laravel

Laravel validation is supported by using the recaptcha validation rule on g-recaptcha-response.

$rules = [
    'g-recaptcha-response' => 'required|recaptcha'
];

$validator = Validator::make(Input::all(), $rules);
$validated = $validator->passes();

$response = '';
if ( ! $validated) {
    $response .= '<pre>' . print_r($validator->errors()->all(), true) . '</pre>';
}

$response .= 'Did I validate? ' . ($validated ? 'Yes.' : 'No.');

return $response;

Errors

If validate() fails, you can get the errors by calling $validator->errors(). This will return an array with codes errors keys. See Error code reference at the documenation website.

If you are using Laravel, errors() will return an instance of Illuminate\Support\MessageBag with all errors translated.

Laravel configuration

There is not really a need to publish the configuration file. Both the siteKey and secretKey should be set in your environment file so it won't be available in your versioning system.

The only option available is to enable or disable curl. So if you're having trouble or don't have access to curl, you can publish the configuration file and change the curl value to false. We will then use file_get_contents instead.

Laravel 5:

php artisan vendor:publish

Laravel 4:

php artisan config:publish marwelln/recaptcha

See Protecting Sensitive Configuration if you don't know how to setup environment variables in Laravel 4.


All versions of recaptcha with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
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 marwelln/recaptcha contains the following files

Loading the files please wait ...