Login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Login

Post by moiseszaragoza »

Hi every one.

I'm Doing a web site using PHP and SQL.

I have a DB for Usernames and Passwords and when a User logs in It has to say Hi Username.
I was wandering how do I get the User name After the log in.

Is there a scrit that has to be in the Log in Page or a Query on the Page after?

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is assuming once logged in their username is set in a session and assuming their username is stored in the `usersname` field.

Code: Select all

<?

$query = "SELECT * FROM `users` WHERE `usersname`='".$_SESSION['username']."'";

$result = mysql_query($query) or die (mysql_error());

$row = mysql_fetch_assoc($result);

echo 'Hello '. $row['username'];

?>
Last edited by John Cartwright on Sun Oct 03, 2004 4:15 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can store the username in a session variable, cookie, or just query for it on every page. Depends on what kind of infrastructure you want to work with. Personally, I query for it on every page. Because all their user information could change from one page to the next. especially their access privledges.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yeah that is what I do also. It's a highly recommended method that various newbie tutorials teach you.
Post Reply