限制用户在未使用javascript登录的情况下访问页面
我制作了一个注册表,从那里数据被存储到本地存储器中。只有在用户成功登录后,它才会重定向到success.html或将用户带回登录页面。我在success.html的开头添加了以下脚本-限制用户在未使用javascript登录的情况下访问页面,javascript,jquery,Javascript,Jquery,我制作了一个注册表,从那里数据被存储到本地存储器中。只有在用户成功登录后,它才会重定向到success.html或将用户带回登录页面。我在success.html的开头添加了以下脚本- <script> if (localStorage.getItem('status') != null) { //redirect to page window.location.href = "success.html"; } else
<script>
if (localStorage.getItem('status') != null)
{
//redirect to page
window.location.href = "success.html";
}
else
{
//show validation message
window.location.href = "login.html"
}
</script>
在这里,我无法将状态设置为“loggedIn”,如果我通过控制台手动设置,success.html将继续加载,就像运行任何无限循环一样。由于成功页面上的以下条件,循环正在发生。即使您在成功页面,它也会重定向,从而导致循环
if (localStorage.getItem('status') != null)
{
//redirect to page
window.location.href = "success.html";
}
换成
if (localStorage.getItem('status') == null)
{
//show validation message
window.location.href = "login.html"
}
另外,我强烈建议不要使用localstorage将用户名和密码发送到客户端。它甚至打破了现有身份验证和授权服务的完整点。强烈建议您不要使用本地存储来登录/存储密码等。本地存储不安全,可以查看和操作。您需要有一个数据库,在一个安全的环境中存储用户名、密码和密码,并具有php登录机制。请避免本地存储用于登录和存储凭据。就安全而言,这一点都不好。请将加密的密钥和凭据存储在数据库中
if (localStorage.getItem('status') == null)
{
//show validation message
window.location.href = "login.html"
}