laravel怎麼加入驗證碼功能
阿新 • • 發佈:2018-12-13
1.我們在專案的根目錄可以找到composer.json這個檔案,加上下邊的程式碼
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"gregwar/captcha": "1.*"
},
2.進入專案根目錄進行composer update
3.設定路由
// 驗證碼的路由
Route::get('captcha','Index\[email protected]');
4.輸出驗證碼
/* 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.在頁面輸出驗證碼
<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事件