Jump to content


Photo

Sessions and variables…


  • Please log in to reply
1 reply to this topic

#1 Mouse

Mouse
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationToo Close to LONDON

Posted 12 April 2006 - 06:52 AM

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.


#2 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 12 April 2006 - 07:58 AM

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:
<form action="checklogin.php" method="post">
<input type="text" name="firstname">
and so on for the other pieces of data.

In the checklogin.php you'd have something like this:
$firstname=$_POST['firstname'];
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:
$_SESSION['userid']=$userid;
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:
$userid=$_SESSION['userid'];
if ($userid==1) {echo "Welcome user number 1";}

Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users