请参阅这篇关于基于 REST 的身份验证的文章(通过 Apache):http ://www.berenddeboer.net/rest/authentication.html
正如您所说,您计划使用 php session 实现自己的身份验证系统,并且我认为是 mysql,那么您将不需要 .htaccess 文件来完成此操作。
就这通过 PHP 而言,我仍然使用经过大量修改的系统,该系统包含在 sitepoint 书籍中,以正确的方式构建您自己的网站。
它基本上需要加载一组控制器功能,这些功能要么与在会话中存储信息有关,要么与数据库检查存储的信息有关。
然后我可以使用这样的东西来限制对某些页面的访问,方法是将其放在其他所有页面之前:
if (!userIsLoggedIn())
{
include "$docRoot/html/main/login.html.php";
exit();
}
if (!userHasRole('Site Admin'))
{
$error = 'Only a website administrator may access this page, your ip address has been logged and a notification sent to our support team as this is considered as an unauthorized access attempt.';
unset($_SESSION['loggedIn']);
include "$docRoot/html/main/accessdenied.html.php";
exit();
}
if (!userHasActiveAccount())
{
$error = 'Sorry but your account has been disabled. For futher information please contact support.';
unset($_SESSION['loggedIn']);
include "$docRoot/html/main/accessdenied.html.php";
exit();
}