这主要涉及安全性,也涉及最佳方法的建议:
我最初设计的网站将为每个选项卡加载一个新的html / php文件,但是最近更改为使用引导程序和导航标签,这样我就没有大量的html文件,并且还可以使网站运行一些更顺畅
当前正在使用方法1 ...
方法1-登录html页面并使用php文件对用户进行身份验证,并在数据库中检查正确的凭据,将会话设置为admin / customer / staff等,然后重定向到所需的页面,如下所示。
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-是否有一种方法可以使用JQuery(或其他方法)隐藏标签内容,除非将会话设置为admin / customer / staff等?如果可能,这安全吗?换句话说,使用登录表单来运行php文件,以检查数据库中的用户凭据并请求用户身份验证级别(admin,staff等)并重定向回索引页面,但打开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');
在“管理”标签内容中打开网站。
预先感谢您对使用的最佳做法有些不确定的人。
为了安全起见,您肯定要进行服务器端验证。您的PHP绝不应呈现用户不应看到的任何HTML。
因此,您的index.html也应该是index.php。
header('Location: https://www.mywebsite.com/index.php');
然后在此文件中重复$_SESSION['auth']
检查。
if (@$_SESSION['auth'] == "Admin")
{
// Render admin tab
}
// ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句