Johntaa / laravel-captcha by Johntaa

Captcha for Laravel PHP Framework
5,305
6
2
Package Data
Maintainer Username: Johntaa
Maintainer Contact: fccffccffccf@yahoo.com (:johntaa)
Package Create Date: 2013-12-24
Package Last Update: 2015-09-11
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-11 15:20:25
Package Statistics
Total Downloads: 5,305
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 6
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

Captcha for Laravel 4.*

For Laravel 5 change to branch masterl5

It is just a copy of https://github.com/mewebstudio/captcha but maintained to serve Laravel framework

A simple Laravel framework service provider for including the Captcha for Laravel framework.

Preview

Preview

Installation

Note: This Script Requires GD extension to be installed

The Captcha Service Provider can be installed via Composer by requiring the mews/captcha package and setting the minimum-stability to dev (required for Laravel 4.1) in your project's composer.json.

{
    "require": {
        "laravel/framework": "4.*",
        "johntaa/captcha": "dev-master" 
    },
    "minimum-stability": "dev"
}

Update your packages with composer update or install with composer install.

Usage

To use the Captcha Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

Find the providers key in app/config/app.php and register the Captcha Service Provider.

    'providers' => array(
        // ...
        'Johntaa\Captcha\CaptchaServiceProvider',
    )

Find the aliases key in app/config/app.php.

    'aliases' => array(
        // ...
        'Captcha' => 'Johntaa\Captcha\Facades\Captcha',
    )

Configuration

To use your own settings, publish config.

$ php artisan config:publish johntaa/captcha

Example Usage


    // [your site path]/app/routes.php

    Route::any('/captcha-test', function()
    {

        if (Request::getMethod() == 'POST')
        {
            $rules =  array('captcha' => array('required', 'captcha'));
            $validator = Validator::make(Input::all(), $rules);
            if ($validator->fails())
            {
                echo '<p style="color: #ff0000;">Incorrect!</p>';
            }
            else
            {
                echo '<p style="color: #00ff30;">Matched :)</p>';
            }
        }

        $content = Form::open(array(URL::to(Request::segment(1))));
        $content .= '<p>' . HTML::image(Captcha::img(), 'Captcha image') . '</p>';
        $content .= '<p>' . Form::text('captcha') . '</p>';
        $content .= '<p>' . Form::submit('Check') . '</p>';
        $content .= '<p>' . Form::close() . '</p>';
        return $content;

    });