身份验证&登录 - Bootstrap - 标签

时间:2018-02-27 13:18:24

标签: php jquery html ajax authentication

这主要是关于安全性,也是关于最佳方法的建议:

我最初设计的网站会为每个标签加载一个新的html / php文件,但最近更改为使用bootstrap并使用nav-tabs,这样我就没有大量的html文件,也无法制作网站运行得更顺畅。

目前使用方法1 ...

方法1 - 登录html页面并使用php文件对用户进行身份验证,并检查数据库中是否有正确的凭据,将会话设置为admin / customer / staff等,然后重定向到所需的页面,如下所示。 / p>

if ($row[0]=='1') // admin login
{
$_SESSION['auth']='Admin';
//redirect to admin page
}
else if ($row[0]=='2') // business login
{
$_SESSION['auth']='Staff';
//redirect to staff page
}

方法2 - 除非会话设置为admin / customer / staff等,否则有没有办法使用JQuery(或其他方法)隐藏选项卡内容?如果可能,这是安全的吗? 换句话说,使用登录表单运行php文件以检查数据库中的用户凭据并请求用户身份验证级别(管理员,员工等)并重定向回索引页面,但要打开admin / staff选项卡内容?与身份验证类似的东西:

if (@$_SESSION['auth'] == "Admin")
{
header('Location: https://www.mywebsite.com/index.html#admin');
}
else if (@$_SESSION['auth'] == "Staff")
{
header('Location: https://www.mywebsite.com/index.html#staff');
}
else
{
//deny access and revert to login screen
}

我要求上面的代码是,这是如何重定向到我的主页,但是使用#staff / #admin?加载tabcontent?那么可以做下面的事吗?

<div role="tabpanel" class="tab-pane fade" id="staff">
//Some code either goes here to only allow access if the session is set to staff
//Alternatively if code doesnt go here, is it possible to use JQuery to target this tabpanel to show this tab if user authentication is staff
</div>

方法3 - 我觉得很难相信,但有人告诉我,正常设置标签并在成功登录尝试后打开标签是安全的。这是真的?如果是这样,我知道我可以使用AJAX进行实时登录,只需将登录指向员工/管理员标签内容

因此,在快速总结中确保我已尽力解释,方法1,2或3最适合性能和安全性。

确实

header('Location: https://www.mywebsite.com/index.html#admin');

在管理标签内容中打开网站。

提前感谢有人不确定使用的最佳做法。

1 个答案:

答案 0 :(得分:3)

为了安全起见,您肯定希望进行服务器端验证。您的PHP不应该呈现用户不应该看到的任何HTML。

因此,您的index.html也应该是index.php。

Username

然后在此文件中重复header('Location: https://www.mywebsite.com/index.php'); 检查。

$_SESSION['auth']