【发布时间】:2013-09-06 01:18:53
【问题描述】:
我网站上的www.example.com/index.html 是一个要求输入密码的页面,输入时会贯穿www.example.com/login.php。
<?php
if (isset($_POST['pw']) && ($_POST['pw'] == "mypassword"))
{
// Location after Logged in
header('Location: http://example.com/kareha/index.html');
}
else
{
// If not Logged in
header('Location: http://example.com/index.html');
}
?>
然后被重定向到www.example.com/kareha/。
问题是,任何人都可以输入并直接导航到www.example.com/kareha/。
有什么方法可以保护这个索引文件(或网站上的任何其他地方),以便将未登录的任何人重定向到主登录页面?
另外,如果通过.htaccess 保护它会有帮助吗? (/kareha/index.html根据模板自动更新,每次乱用就坏了)
编辑:可能类似于使用/login.php 开始会话,然后在/kareha/ 文件夹中使用.htaccess 检查会话?
【问题讨论】:
-
可能无法解决您的问题,但您需要将此
header('Location : http://example.com/kareha/index.html');更改为此header('Location: http://example.com/kareha/index.html');,因为Location和:之间添加的空格会破坏它。 -
没注意到,谢谢!
标签: php .htaccess login passwords