title: retrieve and store other information about a user when they login
body: <p>I have a login script that I am using that is currently working, but I want to add some additional functionality such as displaying name, some prefs etc. I'd like to store the users ID in the session so I can use it as they navigate the site for lookups, but I'm not sure how to go about this. Any help is greatly appreciated... code is below.</p>
  
  <pre><code>&lt;?php
  include_once $_SERVER['DOCUMENT_ROOT'] .
  '/includes/magicquotes.inc.php';
  
  if (isset($_GET['login'])){
  include 'login.html.php';
  exit();
  }
  
  if (isset($_GET['security'])){
  ob_start();
  $host="localhost"; // Host name 
  $username="*****"; // Mysql username 
  $password="*****"; // Mysql password 
  $db_name="*****"; // Database name 
  $tbl_name="users"; // Table name 
  
  // Connect to server and select databse.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // Define $myusername and $mypassword 
  $myusername=$_POST['myusername']; 
  $mypassword=$_POST['mypassword']; 
  
  // To protect MySQL injection (more detail about MySQL injection)
  $myusername = stripslashes($myusername);
  $mypassword = stripslashes($mypassword);
  $myusername = mysql_real_escape_string($myusername);
  $mypassword = mysql_real_escape_string($mypassword);
  $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  $result=mysql_query($sql);
  
  // Mysql_num_row is counting table row
  $count=mysql_num_rows($result);
  
  // If result matched $myusername and $mypassword, table row must be 1 row
  if($count==1){
  
  // Register $myusername, $mypassword and redirect home"
  session_register("myusername");
  session_register("mypassword"); 
  header("location:/admin/");
  }
  
  else {
  echo "Wrong Username or Password";
  }
  ob_end_flush();
  exit();
  }
  
  if (isset($_GET['logout'])){
  session_start();
  session_destroy();
  header("location:/admin/");
  exit();
  }   
  session_start();
  if(!session_is_registered(myusername)){
  header("location:?login");
  }
  
  // Display Home Page
  
  include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
  
  include 'home.html.php';
  exit();
  </code></pre>