View Full Version : Get user info after logging in

01-17-2010, 05:43 AM
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:

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.


01-17-2010, 06:30 AM
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.