How to set sessions?


#1

I’m making a login script, and the register works wonderfully, but I’m having trouble setting a sessions. I already have the users Firstname, Lastname, Email, Password, and Age in the database (each in it’s own column) but I can’t quite set them as variables. When you login it asks for your Email and Password (so I can set the email as a session) but I don’t know how to retrieve their First and Lastnames. How do I? Please help, I’ve been working on this for over a month. Thank you in advance! ;D


#2

On every page you want to use session variables, you need this command at the top of your PHP code:
session_start(); //use only once per page…

Then, to set a session variable, use this command:
$_SESSION[‘variable_name’]; //any name can be use without special chars and caps are important
// if you use caps, like, ‘UserID’, then use them on all pages

To read the session variable:
$testing=$_SESSION[‘variable_name’];
//$testing is your current variable which is loaded with the session variable…

It’s that easy… Good luck…