Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    104
    Thanks
    71
    Thanked 0 Times in 0 Posts

    Exclamation Get user info after logging in

    What's the best way to get a user's info from a database after they login?

    For example, if I want to welcome the user after logging in:

    "Welcome back, [user's first name from database]."

    Now, do i need to repeat my SQL statements each and every time, using something like:

    Code:
    SELECT username, first_name FROM users WHERE username = '$_SESSION['username']'
    Or, does the session that I create when the user logs in remember which user (row) was selected from the database during the first log in?

    I'm confused, because during my tests I only have to access the columns I want without specifying the row I want on the page that the user is redirected to after logging in.

    Thanks!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Store their userid in a session. You can store other common data in a session like first name and last name when they first login however DO NOT store any personal information like passwords and phone numbers. Things you wouldn't really want public to just anyone. You can then use those sessions through out your site. You can also just store their userid in a session and query the database each time you want their information.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •