【发布时间】:2017-10-12 05:24:09
【问题描述】:
我在 apache (2.4) Web 服务器上编写了一个 Web 应用程序,用户通过 kerberos 进行身份验证。我的数据库中有一个用户表,其基本权限(r,w)设置为 0 或 1。现在我想在每次用户尝试访问此 Web 服务器上的页面时检查这些权限。当用户没有读取权限时,他应该被重定向到页面“forbidden.html”。显然,apache 无法进行权限检查。于是我用php试了一下。
我目前所拥有的
我已将所有 html 文件放在 apache DocumentRoot 的子文件夹 /html 中,并将其放入我的配置文件中,以便每次用户在 /html 中请求页面时调用 php/auth.php:
<Location /html>
<If "%{REQUEST_URI} !~ m#\/forbidden\.html#">
# Script checks if user should get access to the site
SetHandler auth-script
Action auth-script "/php/auth.php"
</If>
</Location>
php/auth.php:
if ($params["user"]["r"] == 1) {
// User has permission, redirect to the requested page
header("Location: https://webapp.domain.de".$_SERVER["REQUEST_URI"]);
} else {
// User has no permission, redirect to forbidden.html
header("Location: https://webapp.domain.de/html/forbidden.html");
}
问题
我的问题是我得到了一个重定向循环。似乎来自 auth.php 的 header() 的重定向再次通过 apache 的 Action 指令触发了 auth.php 脚本。当用户被重定向到forbidden.html时不会出现此行为,因为它被排除在conf文件中。
我尝试在 auth.php 中注释掉 header(),但是 apache 不会使用 Action 指令自动为请求的站点提供服务。
有没有办法知道 auth.php 是否已经在这个请求中重定向了用户并告诉 apache 不要调用脚本。还是有更好的方法来实现我想要实现的目标?
提前致谢。
【问题讨论】:
标签: php apache authentication redirect