codeigniter 控制器中的目录
我的 codeigniter 控制器中有两个目录。
/controllers/admin/dashboard.php
- content.php
- enquiries.php
- 因为目录文件夹本身不是控制器,
/controllers/members/
- profile.php
- chat.php
- settings.php
如果用户浏览到根目录,我无法执行任何功能目录的。
例如,如果用户浏览到的
/localhost/admin/
视图将不会被加载,也不会显示 404。这可以让用户知道该目录确实存在,从而给我带来安全风险,因为人们会知道我有一个管理目录。
如果用户浏览到目录文件夹的根目录,怎么可能显示 404 消息???
I have two directories within my codeigniter controller.
/controllers/admin/
- dashboard.php
- content.php
- enquiries.php
/controllers/members/
- profile.php
- chat.php
- settings.php
Because the directory folders are not themselves controllers I can't perform any functions if the user browses to the root of the directory.
Example if the user browses to
/localhost/admin/
a view won't be loaded and will not show a 404. This lets users know that the directory does exist, giving me a security risk because people will know that I have an admin directory.
How is it possible to show a 404 message if the user browses to the root of the directory folder???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 config/routes.php 中添加以下内容:
$route['admin'] = 'errors/page_missing';
$route['members'] = 'errors/page_missing';
... 其中 Errors 是一个具有 page_missing 方法的控制器,您可以在其中加载“未找到文件”视图。
You could add this in config/routes.php:
$route['admin'] = 'errors/page_missing';
$route['members'] = 'errors/page_missing';
... where Errors is a controller with a method of page_missing, where you load a 'file not found' view.
我的方法是在我不想隐藏的目录中创建默认控制器
welcome.php
并添加show_404()函数。像这样:这样,您就不必摆弄路由或重写规则。简单干净。
The way I do it is creating the default controller
welcome.php
in the directories I wan't to hide and add the show_404() function. Like this:This way, you don't have to fiddle with routes or rewrite rules. Simple and clean.