bobocheez Posted August 15, 2009 Share Posted August 15, 2009 Hi, I've looked over a few login tutorials about sessions, but my small brain cannot connect the dots from the different programming styles people have. What I understand so far, and please correct me if I am wrong,: 1. For logins: after a user logs in and the info is processed through the database session variables are set //connect & retrieve database info for bob then: $_SESSION['valid_user'] = $username; $_SESSION['user_id'] = $user_id; //This means that the session array valid_user is = to bob 2. Each page that has the session_start(); function can use those session variables. So if $username is echoed, then the valid_user array would carry over and display bob Therefore if the index page contains the session start function at the beginning, and includes the login form/processor, then any $_REQUEST information should be able to use those stored variables. Now, I figured I must be missing something because the scraps of code that I put together do not work, or I just suck at writing things correctly. Any input (good/bad) is appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/170432-solved-sessions-with-logins/ Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 So if $username is echoed, then the valid_user array would carry over and display bob It would be saved under $_SESSION['valid_user'], not $username Link to comment https://forums.phpfreaks.com/topic/170432-solved-sessions-with-logins/#findComment-899010 Share on other sites More sharing options...
bobocheez Posted August 15, 2009 Author Share Posted August 15, 2009 Oh So, $_SESSION['valid_user'] carries over to all other pages where the session start function is included, and for those pages, $username would have to be set = to the session variable each time. Therefore session_start(); $username = $_SESSION['valid_user']; echo "Hello $username"; Would display Hello bob Is this correct? Link to comment https://forums.phpfreaks.com/topic/170432-solved-sessions-with-logins/#findComment-899013 Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 yes Link to comment https://forums.phpfreaks.com/topic/170432-solved-sessions-with-logins/#findComment-899021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.