简体   繁体   English

我们有一个基本的登录功能可以登录,但是随后突然返回到登录屏幕

[英]We have a basic login function that logs in, but then it abruptly goes back to the login screen again

So why does it go back to the login screen again? 那么,为什么又回到登录屏幕呢? what have we missed here? 我们在这里错过了什么?

user: admin 用户:admin

pass: 1234 通过:1234

so we have a simple login solution (I know pass and user will be visible in the source but this is just a school project to learn php so it doesn't really matter for us in this case.) 所以我们有一个简单的登录解决方案(我知道pass和user在源代码中都是可见的,但这只是一个学习php的学校项目,因此在这种情况下对我们来说并不重要。)

this is the relevant code: 这是相关代码:

<head>
   <script>
    var usr ='admin';
    var psw = '1234';
    var loggedIn=false;

    function loggaIn() {
        if ( ($('#idUser').val()== usr) && ( $('#idPsw').val()== psw ) )
        {
            loggedIn=true;
            $('#logdiv').toggle();
            $('#mainOK').toggle();

        }
        else
        {
            alert ("Incorrect username and/or password!")   
        }
    }

    function loggaut() {
        loggedIn=false;
        $('#mainOK').hide();
        $('#loggin').show();

    }
    </script>
</head>

<body>
    <input type="text" id="idUser" placeholder="Username">
    <input type="text" id="idPsw" placeholder="Password">
    <br>
    <button onclick="loggaIn()" class="pure-button pure-button-primary">Log in</button>
</body>

Any tips or help towards finding a solution would be much appreciated 任何提示或寻求解决方案的帮助将不胜感激

You are doing it wrong. 你做错了。 Such credentials should never be tested in JS code. 此类凭据永远不应在JS代码中进行测试。 It is harmful. 这是有害的。 I totally agree with @void. 我完全同意@void。

POST your username/password to PHP & then decide whether to display inner page or redirect back to login again. 将您的用户名/密码发布到PHP,然后决定是显示内部页面还是重定向回再次登录。

You should learn how to manage login/session using PHP. 您应该学习如何使用PHP管理登录/会话。 Here is good resource for you: http://www.sitepoint.com/users-php-sessions-mysql/ 这是为您提供的很好的资源: http : //www.sitepoint.com/users-php-sessions-mysql/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript基本登录功能 - Javascript Basic Login Function 如何实现注销操作返回登录页面的功能? - How do I implement the function of logout action goes back to login page? Supress登录屏幕,用于JS Metro App中的基本身份验证 - Supress login screen for basic authentication in JS Metro App 即使注册通过并登录用户,解析服务器js也无法登录用户 - parse-server js can't login user, even though registration goes through and logs user in React native - 防止用户返回登录屏幕 - React native - prevent user from going back to login screen 如果我们创建了一个 function 来替换它,如何在 textarea 中再次插入点(。)? - How to Insert dot(.) again in textarea, if we have created a function to replace it? 滚动到指定位置时,如果我们再次返回到该位置,将启动该功能,如何将其重置并重新启动? - When scroll to a specified place, starts the function, how to reset it and start again, if we go back again to this place? 我试图在登录后将用户重定向到欢迎页面,这需要我进入欢迎页面,然后再次将我重定向回登录页面 - I am trying to redirect user after login to welcome page, it takes me to welcome page and again re directs me back to login page 检查用户是否已经拥有帐户的登录系统。 如果他们有,那么他们可以登录,如果他们没有,那么他们必须再试一次 - Login system that checks out if the user already has an account. If they have one then they get to login, if they don't then they must try again 当访问令牌到期时我们如何保持用户登录,我们需要再次登录才能以普通用户身份继续 - How can we maintain user logged in when access token expires and we need to login again to continue as normal user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM