I remember having a similar problem i searched around and found the code i used and it works. i hope it helps.
//login.html
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="POST" action="login.php">
Username: <input type="text" name="username" size="20">
Password: <input type="password" name="password" size="20">
<input type="submit" value="Login" name="login">
</form>
</body>
</html>
//login.php code
<?
if (!isset($POST['username']) || !isset($POST['password']))
{
header("Location: login.htm");
}
elseif (empty($POST['username']) || empty($POST['password']))
{
header("Location: login.htm");
}
else
{
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "dbname";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select
database $DBName");
$sqlquery = "SELECT * FROM users WHERE username='$user' AND password='$pass'";
$result = mysql_query($sqlquery);
//mysql_close();
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0)
{
while($row = mysql_fetch_array($result))
{
session_start();
session_register('username');
//echo 'You have successfully logged in';
header("Location: checkLogin.php");
}
}
else
{
echo 'Login Failed';
}
}
?>
//checklogin.php check that your logged in
<?
session_start();
if(session_is_registered('username'))
{
echo'Welcome you are still logged in';
}
else
{
header("Location: http://localhost/login.htm");
}
?>
//logout.php logout code
<?
session_start();
if(session_is_registered('username'))
{
session_unset();
session_destroy();
echo'You are now logged out of the system';
}
else
{
header("Location: http://localhost/login.htm");
}
?>
if you have any probs give me a shout and ill see if i can help but it works for me.