name sessions from post variables

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
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

name sessions from post variables

Post by snpo123 »

i am trying to create and name sessions from post variables and i am not quite sure how to do it. here is what i have so far:

session_start();
$_SESSION['{$_POST['name']}'];
$_SESSION['{$_POST['email']}'];

i know this is completly wrong, and I was wondering if someone could help me do it right

thanks
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

i believe you simply just want:

$_SESSION["user"] = $_POST["username"];
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

Post by snpo123 »

duh, i am such an idiot...lol
thnx man
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

Post by snpo123 »

wait... how would I print the value of that session on another page?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you would need

session_start(); at on line1

then:

echo $_SESSION['sessionname'];
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Phenom is most correct.

any page you wish to access session variables must have a session_start();

But - I would assign it to a variable, ie:

$user = $_SESSION['username'];

echo $user;

Makes it so you dont have to keep typing $_SESSION cause if your like me, i always forget to make the underline and $SESSION, oh well! lol

:wink:
Post Reply