Jump to content

I want to display 'Welcome userid!' after user successfully logged in


Jellyphp

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.