Page 1 of 1

Login

Posted: Sun Oct 03, 2004 4:09 pm
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

Posted: Sun Oct 03, 2004 4:14 pm
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'];

?>

Posted: Sun Oct 03, 2004 4:14 pm
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.

Posted: Sun Oct 03, 2004 4:18 pm
by m3mn0n
Yeah that is what I do also. It's a highly recommended method that various newbie tutorials teach you.