I am new in php and new in this site.
I have made a login code. when people login, and then click other links, they are logged out. Also, sometimes when people login, it show someone else's name. However, clear cache and clean the browser's history, everything is good then. What is the problem can cause this situation?
<?php
ob_start();
ob_start('gz_handler');
session_start();
require_once("loginconfig.php");
if (isset($_POST['username']) && strlen($_POST['username']) >= 3 && isset($_POST['password']) && strlen($_POST['password']) >= 3)
{
$connect = mysql_connect($host, $user, $pass);
mysql_select_db($database, $connect);
$usernameTest = $_POST['username'];
$passwordTest = $_POST['password'];
$usernameTest = htmlentities($usernameTest, ENT_QUOTES);
$passwordTest = htmlentities($passwordTest, ENT_QUOTES);
//$passwordTest = md5($passwordTest);
$query = mysql_query("SELECT $username, $password, $name, $accessLevel FROM $table WHERE $username='$usernameTest' AND $password='$passwordTest'", $connect);
$affectedRows = mysql_num_rows($query);
if($affectedRows === 1)
{
$rows = mysql_fetch_array($query);
$_SESSION['username'] = $rows[$username];
$_SESSION['name'] = $rows[$name];
$_SESSION['accessLevel'] = $rows[$accessLevel];
$_SESSION['auth'] = strlen($rows[$username].$rows[$password]);
$query = mysql_query("UPDATE $table SET LastLogin=NOW() WHERE $username='$usernameTest' AND $password='$passwordTest'", $connect);
mysql_close($connect);
header("Location: $loggedIn");
ob_flush();
}
else
{
header("Location: $homePage?e=2");
ob_flush();
}
}
else
{
header("Location: $homePage?e=1");
ob_flush();
}
?>