Forum Moderators: coopster

Message Too Old, No Replies

Maintaining user information throughout session

How to do it?

         

megajam02

1:35 pm on Oct 27, 2004 (gmt 0)

10+ Year Member



Ok guys, you have been so helpful in the past. Here's another one for you..

I am developing a protected section of my companies website where customers can register and obtain access to forums, whitepapers, etc.

I have developed the login page, profile pages, etc, but one thing I dont know how to do it make sure that as long as my user is logged in, if they click on the "Profile" link, they will see their, and ONLY their user profile info.

I am investigating global and/or session variables to keep the 'userid' field in memory throughout the session and provide me with a way of always identifying the user.

Am I going down the right path? Any suggestions on where to look, ie - tutorials or something?

Thanks,
Chris

dreamcatcher

2:09 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to register a session variable that will be unique for that visitor, then pull the data for that visitor based on this field. Maybe a username or email address?

$_SESSION['username'] = '$username';

if (isset($_SESSION['username']))
{
mysql_query("SELECT * FROM table WHERE username = '" . $_SESSION['username'] . "' LIMIT 1") or die(mysql_error());
}

Maybe something like that?

megajam02

2:26 pm on Oct 27, 2004 (gmt 0)

10+ Year Member



It worked. Youre the man.

:)

Thanks so much.

Chris

dreamcatcher

6:44 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You`re welcome. :)