Jump to content

Sessions and variables…


Mouse

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

Mouse.
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.