I am new to php, so I'm afraid this may be a complete noob question, but I can't figure it out.
I have a log in system on my site which links to the database and checks user names/passwords. That code works correctly I'm sure. I am able to start a session in that code and print the output I place into the session variables, but what I am not understanding is how to use those session variables in the other site php files.
For ex. From the logIn.php (where the session is started) if they click on the link to profile.php I want the session variables 'username' and 'password' to be transferred to profile.php so that the code can display the profile information corresponding to the users account.
The point of sessions is to pass variables between all the pages in a site correct?
I'm just missing a key point for how to do this.
Session Question - Site Log In
Moderator: General Moderators
-
taraxgoesxboom
- Forum Newbie
- Posts: 5
- Joined: Tue Jan 25, 2011 2:22 pm
-
sockpuppet
- Forum Newbie
- Posts: 22
- Joined: Tue Jan 18, 2011 8:38 am
Re: Session Question - Site Log In
Put session_start(); on top of each page you want to use sessions in.
Then $_SESSION['username'] to get at the variable.
Then $_SESSION['username'] to get at the variable.
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: Session Question - Site Log In
Well I started writing a reply and saw that SockPuppet was quicker on the draw. But yeah, use session_start() not just to create a session but to resume the current one.
-
taraxgoesxboom
- Forum Newbie
- Posts: 5
- Joined: Tue Jan 25, 2011 2:22 pm
Re: Session Question - Site Log In
Worked beautifully, thank you.