unodepiera/simplecaptcha

There is no license information available for the latest version (dev-master) of this package.

simplecaptcha package for laravel 4

dev-master 2013-12-11 20:44 UTC

This package is not auto-updated.

Last update: 2024-04-23 05:07:53 UTC


README

##Installation

{
	"require": {
	    "laravel/framework": "4.0.*",
	    "unodepiera/simplecaptcha": "dev-master"
	},
	"minimum-stability": "dev"
}

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

Usage

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

	'providers' => array(
        //...
        'Unodepiera\Simplecaptcha\SimplecaptchaServiceProvider',
    )

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

	'aliases' => array(
        //...
        'Simplecaptcha'  => 'Unodepiera\Simplecaptcha\Facades\Simplecaptcha',
    )

Publish assets with this command.

$ php artisan asset:publish unodepiera/simplecaptcha

Options captcha

You can set the following options for the captcha.

	$defaultOptions = array(
		"font"			=>	"PT_Sans-Web-Regular.ttf",
		"width" 		=> 	250,
		"height" 		=> 	140,
		"font_size" 	=> 	25,
		"length" 		=> 	6,
		"num_lines" 	=> 	"",
		"num_circles" 	=> 	"",
		"text"			=>	"",
		"expiration"	=>	600,
		"directory"		=>	"packages/unodepiera/simplecaptcha/captcha/",
		"dir_fonts"		=>	"packages/unodepiera/simplecaptcha/fonts/",
		"type"			=>	"alpha",
		"bg_color"		=>	"181,181,181",
		"border_color"	=>	"0,0,0"
	);
  • Font: type font for captcha, view folder public/fonts.
  • Num_lines: number lines you would for captcha.
  • Num_circles: number circles you would for captcha.
  • Expiration: number of seconds it will take to be removed captchas.
  • Directory: folder on save captchas.
  • Dir_fonts: directory on save the fonts.
  • Type: alpha or alphanum.

Example Usage

	Route::get("form", function()
	{

		$options = array(
			"width"			=>	280,
			"height" 		=> 	100,
			"font_size" 	=> 	28,
			"length" 		=> 	8,
			"num_circles" 	=> 	0,
			"num_lines" 	=> 	4,
			"expiration"	=>  600,
			"bg_color"		=>	"20,20,20"
		);

		$captcha = Simplecaptcha::captcha($options);
		return View::make("form", array("captcha" => $captcha));

	});
	Route::post("process", function()
	{
		$rules =  array('captcha' => array('required', 'captcha'));
	    $validator = Validator::make(Input::all(), $rules);
	    if($validator->fails())
	    {

	    	echo "fails";

	    }else{

	    	echo "success";
	    	
	    }
	});

Now you can use the captcha in the view as follows:

    <table>
        {{ Form::open(array('url' => 'process')) }}
        <tr>
	        <td>
	        </td>
	        <td>
	            {{ $captcha["img"] }}
	        </td>
        </tr>
        <tr>
            <td>
                {{ Form::label('captcha', 'Captcha') }}
            </td>
            <td>
                {{ Form::text('captcha') }}
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                {{ Form::submit('Success') }}
            </td>
        </tr>              
            {{ Form::close() }}
  </table>    

Visit me