Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2010, 04:43 AM   PM User | #1
four0four
Regular Coder

 
Join Date: Jun 2008
Posts: 104
Thanks: 71
Thanked 0 Times in 0 Posts
four0four is an unknown quantity at this point
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!
four0four is offline   Reply With Quote
Old 01-17-2010, 05:30 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:30 PM.


Advertisement
Log in to turn off these ads.