Jump to content


This topic is now archived and is closed to further replies.


Sessions and variables…

Recommended Posts

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 thanks


Share this post

Link to post
Share on other sites

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:
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:
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:
if ($userid==1) {echo "Welcome user number 1";}[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.