This topic is locked

using SESSION var after successful login

4/20/2007 12:40:23
PHPRunner General questions
K
kenmag author

Hi,
I am attempting to perform a query upon a successful login and assign the returned value to a session variable.
I have a users table:
UserID (autoincement)

Name

DisplayName

UserPassword
The security page is set to use the users table with the "name" column as the user name and the "userpassword" as the password column.
I want to look up the "DisplayName" based on the Name used to log in and assign it to $_SESSION["DisplayName"]. I can then use this display name in other places.

What code should I add to my "AfterSuccessful Login" event? It is not clear to me how to use the SESSION["OwnerID"] variable in my query.

Base on my table above, what would the code snippet look like?
Any hints would be appreciated.

T
thesofa 4/22/2007

the basics of what you need are covered in this post about getting user ID information.

J
Jane 4/23/2007

Hi,
here is sample code:

global $conn;

$str = "select DisplayName from users where Name='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

//save value in the session variable

$_SESSION["DisplayName"] = $data["DisplayName"];