title: Redirect to home page after login php
body: <p>I've created a login-form. How can I make so that when a user logs in he/she redirects to a page where it displays his/her name? I've walked through many tutorials on how to do this, but nothing was pretty good...</p>
  
  <p>main_login.php:</p>
  
  <pre><code>&lt;table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"&gt;
  &lt;tr&gt;
  &lt;form name="form1" method="post" action="checklogin.php"&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;&lt;strong&gt;Member Login &lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="78"&gt;Username&lt;/td&gt;
  &lt;td width="6"&gt;:&lt;/td&gt;
  &lt;td width="294"&gt;&lt;input name="myusername" type="text" id="myusername"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Password&lt;/td&gt;
  &lt;td&gt;:&lt;/td&gt;
  &lt;td&gt;&lt;input name="mypassword" type="text" id="mypassword"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input type="submit" name="Submit" value="Login"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/form&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>login_success.php:</p>
  
  <pre><code>&lt;?php
  session_start();
  if(!session_is_registered(myusername)){
  header("location:http://main_login.php");
  }
  ?&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  Login Successful
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>checklogin.php:</p>
  
  <pre><code>&lt;?php
  
  $host="host"; // Host name 
  $username="username"; // Mysql username 
  $password="password"; // Mysql password 
  $db_name="database"; // Database name 
  $tbl_name="table"; // 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");
  
  // username and password sent from form 
  $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 to file "login_success.php"
  session_register("myusername");
  session_register("mypassword"); 
  header("location:login_success.php");
  }
  else {
  echo "Wrong Username or Password";
  }
  ?&gt;
  </code></pre>