Jump to content

[SOLVED] sessions with logins


bobocheez

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.