title: Auto login after registration PHP
body: <p>I designed a web site that allows user to register with a simple html form. I want the user, after validating registration to be redirected to the home page and display this message for the new user "Account created" , I found many answers on the internet but all of them are old and different -that was confusing-  I would like to get the newest and the most efficient way to do this. </p>
  
  <p>This is my log in code</p>
  
  <pre><code> &lt;?php // rnlogin.php
   include_once 'rnheader.php';
  echo "&lt;h3&gt;Member Log in&lt;/h3&gt;"; 
  $error = $user = $pass = "";
  if (isset($_POST['user'])) 
  {
  $user = sanitizeString($_POST['user']);
  $pass = sanitizeString($_POST['pass']);
  if ($user == "" || $pass == "")
      {
      $error = "Not all fields were entered&lt;br /&gt;";
      }
      else
          {
          $query = "SELECT user,pass FROM rnmembers
              WHERE user='$user' AND pass='$pass'";
      if (mysql_num_rows(queryMysql($query)) == 0)
          {
          $error = "Username/Password invalid&lt;br /&gt;";
          }
          else
              {
              $_SESSION['user'] = $user;
              $_SESSION['pass'] = $pass;
              die("You are now logged in. Please
                  &lt;a href='rnmembers.php?view=$user'&gt;click here&lt;/a&gt;.");
              }
              }
              }
   echo " &lt;form method='post' action='rnlogin.php'&gt;$error Username &lt;input type='text' maxlength='16' name='user'
              value='$user' /&gt;&lt;br /&gt; Password &lt;input type='password' maxlength='16' name='pass'
                  value='$pass' /&gt;&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
                      &lt;input type='submit' value='Login' /&gt; &lt;/form&gt;"
  ?&gt;
  </code></pre>
  
  <p>and this is the code on my home page that create the session</p>
  
  <pre><code>include_once 'rnheader.php';
  if (!isset($_SESSION['user']))
  die("&lt;br /&gt;&lt;br /&gt;You must be logged in to view this page");
  $user = $_SESSION['user'];
  </code></pre>