retrieving $username from $_SESSION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

retrieving $username from $_SESSION

Post by glennn3 »

I had started a site with a pretty uncomfortable username/password auth. script with which i also queried the database membership list, of course... the script became a bit too cumbersome and i swapped it out with a sessions auth. script like so:

Code: Select all

function cleanMemberSession($username, $password) {

$_SESSIONї"username"]=$username;
$_SESSIONї"password"]=$password;
$_SESSIONї"loggedIn"]=true;
}
now that i've gone and done this, the only problem i have is getting the $username variable into the query form without carrying it around all over the site posting and getting it in the url string (seems a bit redundant to me..., plus it'd be nuts to rewrite all the links with ?username=$username...)

i realize my inexperience is showing. i'm just hoping there's gotta be a way to translate the session that's registered into the username variable that's registered along with it when i need to in one script instead of totin' it around in all the urls...

am i asking the right question? making any sense?

i appreciate the help...

glenn
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

Just keep the session going for the duration of the user's visit (on every page). Then $_SESSION["username"] will always be accessible and you can print it when/where you need to, without having to put it on every link.

peace
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

very nice thank you. god i love this stuff.
Post Reply