title: Login and redirect to user home page
body: <p>The problem I can't currently solve is when a user logs in. They arrive at the site (index.php) and enter username and password, which gets submitted via a Post form back to index.php - if there are incorrect details then they get an error message. But if successful then I would like them to be taken to their user home page - but I can't do this! I am left presenting them with a link to the home page, which is more than a little clunky.</p>
  
  <p>Seems there must be an obviously solution - never seen a site before that didn't redirect! Not sure is the answer is PHp, HTML, or Javascript.</p>
  
  <p>EDIT:</p>
  
  <p>Sorry if the question wasn't up to scratch - still learning here. Have tried to put the redirect in an if statement but still won't work. I think ideally the redirect would be top of the code, but can't see how to do that and retain the login procedure? Code as follows:</p>
  
  <pre><code>if (isset($_POST['user']))
  {
  $user = sanitizeString($_POST['user']);
  $pass = sanitizeString($_POST['pass']);
  
  $salt = "randomsalt";
  $md5pass = md5($salt . $pass);
  
  if ($user == "" || $pass == "")
  {
      $error = "Not all fields were entered&lt;br /&gt;";
  }
  else
  {
      $query = "SELECT username,password FROM users
                WHERE username='$user' AND password='$md5pass'";
  
  
      if (mysql_num_rows(queryMysql($query)) == 0)
      {
          $error = "Username/Password invalid&lt;br /&gt;";
      }
      else
      {
          $_SESSION['user'] = $user;
          $_SESSION['pass'] = $pass;
  
          header("Location: http://localhost:8888/profile.php?view=$user");
  
          exit;
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks</p>
  
  <p>Rich</p>
  
  <p>EDIT 2:</p>
  
  <p>Thanks for your help guys - still couldn't resolve then need to have the re-direct at the top of the page, but equally having to have my login script in place. In the end solved it with:</p>
  
  <pre><code>echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=profile.php?view=$user\"&gt;";
  </code></pre>
  
  <p>In place of the header and exit rows above.</p>
  
  <p>Thanks again</p>
  
  <p>Rich</p>