Basic laravel route password protection without setting up database?(基本的laravel路由密码保护而不设置数据库?)
问题描述
我正在为域 (example.com/demo) 寻找一个死的简单密码保护解决方案(用户名和密码存储为数组中的键值对).我知道这在生产中是不好的做法,但这只是对某人的快速演示.我目前拥有的代码非常简单:
I'm looking for a dead simple password protection solution (username and password stored as key-value pair in array) to a domain (example.com/demo). I know this is bad practice in production but this is just a quick demo to someone. The code I have currently is pretty trivial stuff:
Route::group(['prefix' => 'demo', 'before' => 'auth.basic'], function() {...});
我必须创建自己的过滤器吗?我将如何设置它以使过滤器仅在生产中有效?
Would I have to create my own filter? How would I set it so the filter only works in production?
推荐答案
这很简单:
Route::filter('auth.verybasic', function()
{
if(Request::getUser() != 'foo' || Request::getPassword() != 'bar'){
$headers = array('WWW-Authenticate' => 'Basic');
return Response::make('Invalid credentials.', 401, $headers);
}
});
关于环境限制,只需检查 App::environment():
Regarding the environment restriction, just check with App::environment():
Route::filter('auth.verybasic', function()
{
if(App::environment() != 'production') return;
// check login (same as above)
});
这篇关于基本的laravel路由密码保护而不设置数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:基本的laravel路由密码保护而不设置数据库?
基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
