Created
September 1, 2014 12:24
-
-
Save e2kaneko/6e6233a198dc88be1630 to your computer and use it in GitHub Desktop.
LaravelのルートフィルターでIP制限を実現する ref: http://qiita.com/kaneko_tomo/items/1b0ccdcb7871bf982e3b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 略 | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | 管理画面情報 | |
| |-------------------------------------------------------------------------- | |
| */ | |
| 'admin' => [ | |
| 'allowipaddresses' => ['127.0.0.1', '100.100.100.100'], | |
| ], | |
| // 略 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 略 | |
| Route::filter('auth.allowipaddresses', function($request) { | |
| $clientIp = Request::getClientIp(); | |
| $allowIpaddresses =Config::get('app.admin.allowipaddresses'); | |
| if(!in_array($clientIp, $allowIpaddresses)){ | |
| // 許可されていないIPアドレスからの接続はトップにリダイレクト | |
| return Redirect::to('/'); | |
| } | |
| }); | |
| // 略 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 略 | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | 管理画面 | |
| |-------------------------------------------------------------------------- | |
| */ | |
| Route::group(['before' => ['force.ssl', 'auth.allowipaddresses', 'auth.admin']], function() { | |
| Route::controller('admin', 'AdminController'); | |
| }); | |
| // 略 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment