Ok here are some details. I have a site where its got 2 main columns, one on the left and one on the right which is the main section. I have my menu using a GET script so that it will load the pages on the right side , ie. CONTACT's link is index.php?page=contact
Ok so on my login page I have this code:
<?php
include 'connect.php';
include 'functions.php';
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = pg_query($query);
$numrows = pg_numrows($result);
if ($numrows < 1){
echo "
<form action=\"index.php?page=login\" method=\"POST\">
User: <input type=\"text\" size=\"10\" name=\"username\">
Pass: <input type=\"password\" size=\"10\" name=\"password\">
<input type=\"submit\" value=\"Login\" name=\"login\">
</form>
";
}else{
echo "sup you are already logged in!";
}
if ($_POST['login']){
$username = pg_escape_string($_POST['username']);
$password = pg_escape_string($_POST['password']);
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = pg_query($query);
$numrows = pg_numrows($result);
if ($numrows > 0){
$_SESSION['username'] = $username;
$username = $_SESSION['username'];
echo "Hello $username , you are logged in, this page will refresh soon";
}else{
echo "You are not logged in, bad user/pass";
}
}
?>
and on index.php I have session_start() at the top. The problem is that on login.php , when I login with correct username and passowrd it says "Hello theusername, you are logged in, this page will refresh soon"
So then I click the homepage and then go back to login page and the login form is still coming up! if I logged in just fine and the username was stored then it shouldnt load the form on login.php according to if statement I have saying dont show the form unless the person isnt already logged in.
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = pg_query($query);
$numrows = pg_numrows($result);
if ($numrows < 1){
echo "
<form action=\"index.php?page=login\" method=\"POST\">
User: <input type=\"text\" size=\"10\" name=\"username\">
Pass: <input type=\"password\" size=\"10\" name=\"password\">
<input type=\"submit\" value=\"Login\" name=\"login\">
</form>
";
}else{
echo "sup you are already logged in!";
}
So why isnt it remembering that I just logged in?