I have a odd, but Im sure simple, login issue. When I use my code here, I have a problem with the session section. Validating the login info works fine, but it does not redirect on successful login. If I comment out the session info, it works fine. This happens on both my process-login.php page as well as my success.php page. Any thoughts would be appreciated.
Thank you in advance.
Here is my login page:
<form action="process-login.php" method="post">
<fieldset>
<legend>Login Form</legend>
<label for="username">Username:</label>
<input type="text" id="username" name="username" />
<label for="password">Password:</label>
<input type="password" id="password" name="password" />
<button type="submit">Send</button>
</fieldset>
</form>
Here is my process-login page:
<?php
ob_start();
// Set form data as variables
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
// DB login
$host="localhost";
$username="root";
$password="pass1";
$db_name="contact";
$tbl_name="users";
// Open database connection
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Query with data
$query="SELECT * from $tbl_name where username='$myusername'
and password='$mypassword'";
$result=mysql_query($query);
// Check for entry
$count=mysql_num_rows($result);
// If it matches register and send on
if($count==1){
session_start("username");
session_start("password");
header("location:success.php");
}
else {
echo "Wrong!";
}
ob_end_flush();
?>
And finally, here is my success page:
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:login.php");
}
else
{
echo "Welcome";
}
?>
Please let me know if you need more information