Jellyphp Posted February 4, 2017 Share Posted February 4, 2017 i want to display 'Welcome userid!' after user has successfully logged in. I managed to display it after successfully logged in, but when the user key in the wrong userid and password, the 'Welcome userid' is also displayed. What should i do about it? Below are my coding: login.html processLogin.php index.html Quote Link to comment https://forums.phpfreaks.com/topic/303099-i-want-to-display-welcome-userid-after-user-successfully-logged-in/ Share on other sites More sharing options...
mac_gyver Posted February 4, 2017 Share Posted February 4, 2017 I want to display 'Welcome userid!' after user successfully logged in at the point you have correctly authenticated the user, you would store the user id (the auto-increment column value from your user table) in a session variable. then, on any page where you want to reference any of the user data, you would test if there is a logged in user (the session variable has a value in it) and then query for the user's data using the id stored in the session variable. your login form processing code isn't any place you would display the user's data. its purpose is to log the user in/authenticate the user. and in fact, if the user is already logged in, you wouldn't run the login form processing code or display the login form. your login form processing code should also not be mixed in with the html on your page. it should come before the start of your html document. the form processing code should also first detect if a form has been submitted before referencing any of the form data. you would also validate the submitted form data before using it and you would test if the SELECT query matched a row before using the data from the query (your current logic allows an empty submitted password and a non-existent user to trigger the login logic.) you also need to store the hash of the password when the user registers, and check if the submitted password matches the stored hash in the login code (see php's password_hash() and password_verify() functions.) lastly, if you put the form processing code and the form on the same page (putting the form processing code inside conditional logic that has tested if a form has been submitted is about all you need to do to combine the code into one file), you won't have to mess around with providing a link to return to the form when the login fails. this will reduce the amount of work the user has to do to use your site and will eliminate repetitive html you have to write and maintain. Quote Link to comment https://forums.phpfreaks.com/topic/303099-i-want-to-display-welcome-userid-after-user-successfully-logged-in/#findComment-1542289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.