unodepiera / simplecaptcha
该包最新版本(dev-master)没有可用的许可证信息。
laravel 4 的 simplecaptcha 包
dev-master
2013-12-11 20:44 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.0.x
This package is not auto-updated.
Last update: 2024-09-24 07:12:30 UTC
README
##安装
{
"require": {
"laravel/framework": "4.0.*",
"unodepiera/simplecaptcha": "dev-master"
},
"minimum-stability": "dev"
}
使用 composer update 更新您的包或使用 composer install 安装。
使用方法
在 app/config/app.php 中找到 providers 键并注册 Captcha 服务提供者。
'providers' => array( //... 'Unodepiera\Simplecaptcha\SimplecaptchaServiceProvider', )
在 app/config/app.php 中找到 aliases 键。
'aliases' => array( //... 'Simplecaptcha' => 'Unodepiera\Simplecaptcha\Facades\Simplecaptcha', )
使用以下命令发布资源。
$ php artisan asset:publish unodepiera/simplecaptcha
captcha 选项
您可以为 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" );
- 字体:captcha 的字体类型,查看文件夹 public/fonts。
- Num_lines:captcha 的线条数量。
- Num_circles:captcha 的圆圈数量。
- Expiration:captcha 被删除所需的时间(秒数)。
- Directory:保存 captcha 的文件夹。
- Dir_fonts:保存字体的目录。
- Type:alpha 或 alphanum。
示例用法
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"; } });
现在您可以在视图中按照以下方式使用 captcha
<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>