Mouse Posted April 12, 2006 Share Posted April 12, 2006 Sessions and variables…Dear all,The idea of sessions is a new one to me… and I have what is a basic question. When a user registers for my site I ask for and record $first_name, $last_name and $email_address and a random password is assigned to each user. When they log in to the site their email ($email_address) is checked against their password and all is well, they enter…How do I call the $first_name, $last_name, and $email_address variables into a page so that I can use them to automatically populate user fields in contact forms etc? Many thanksMouse. Link to comment https://forums.phpfreaks.com/topic/7171-sessions-and-variables%E2%80%A6/ Share on other sites More sharing options...
Yesideez Posted April 12, 2006 Share Posted April 12, 2006 Hi,When you define the <FORM> part of the HTML file you need to make a note of the names you called $first_name, $last_name and $email_address. For example:[code]<form action="checklogin.php" method="post"><input type="text" name="firstname">[/code]and so on for the other pieces of data.In the checklogin.php you'd have something like this:[code]$firstname=$_POST['firstname'];[/code]This will grab the data from the form and assign it into the variables you choose.With session variables, these are pieces of data that are held on the server and can hold almost any data you want. For example, if a user logs in OK then you might want to set a session variable with their user ID number taken from a database:[code]$_SESSION['userid']=$userid;[/code]Hope this helps.btw, as long as you start your script with the PHP function "session_start()" then the session variable can be accessed and the contents retrieved and checked like this:[code]$userid=$_SESSION['userid'];if ($userid==1) {echo "Welcome user number 1";}[/code] Link to comment https://forums.phpfreaks.com/topic/7171-sessions-and-variables%E2%80%A6/#findComment-26109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.