1.咱們在項目的根目錄能夠找到composer.json這個文件,加上下邊的代碼php
"require": { "php": ">=5.5.9", "laravel/framework": "5.2.*", "gregwar/captcha": "1.*" },
2.進入項目根目錄進行composer update html
3.設置路由laravel
// 驗證碼的路由 Route::get('captcha','Index\RegisterController@code');
4.輸出驗證碼json
/* author:咔咔 address:陝西西安 wechat:fangkangfk */ // 驗證碼 public function code() { $builder = new CaptchaBuilder(); $builder->build(150,32); $phrase = $builder->getPhrase(); //把內容存入session Session::flash('milkcaptcha', $phrase); //存儲驗證碼 ob_clean(); return response($builder->output())->header('Content-type','image/jpeg'); }
5.在頁面輸出驗證碼session
<img src="{ {url('captcha')}}" style="width: 130px;height: 60px;margin-left: 410px;position: relative;top: -74px;" onclick="this.src=this.src+'?'+Math.random()" class="code" >
6.點擊驗證碼進行刷新,就是onclick事件composer