我在PHP中遇到了URL路由问题。
在我的本地主机中,我有两个项目目录:
-
- 项目(_O):
- index.php
- 其他目录
- 项目(_O):
-
- hacking_script:
- index.php
- database_dump.php
- hacking_script:
当我必须访问我的项目时,我使用localhost/project_one
,这项工作是正确的。但是当我在这个localhost/project_one/../../hacking_script
中有输入时,它是打开的localhost/hacking_script/index.php
文件。
所以我不知道如何预防。我可以使用.htaccess来阻止它吗?如果是,那么怎么做?
如果你谈论的是路由,那么你谈论的就是:
Request -> Router -> GetController -> ExecuteAction
这意味着GetController
将最喜欢include
或require
的一些文件。。。有一部分,你需要确保,它只需要允许的文件。例如,使用白名单(这是推荐的方式)。或者确保不允许使用像../
这样的特殊字符。
这就是URL在浏览器中的工作方式。如果你有这个问题的网站:
http://stackoverflow.com/questions/36980771
如果你尝试:
http://stackoverflow.com/users/../questions/36980771
这将重定向到同一页面。这是按设计的状态。