the main page has a couple extra <html> and <body> tags. you should fix that.
The probelm i think you are having is that you need to store login status across multiple pages. I usually use session for this. However there is a lot of baggage that can go along with them.
Here is a script i wrote, you might be able to modify it, or at least get some ideas from it.
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['form'])==true){
if(strcmp($_POST['form'],'login')==0){
if(isset($_POST['lusername'])){
$_SESSION['username']=$_POST['lusername'];
}
if(isset($_POST['lpassword'])){
$_SESSION['password']=$_POST['lpassword'];
}
}
}
}
if (isset($_SESSION['username'])==false || isset($_SESSION['password'])==false){
echo loginform();
exit;
} else {
if(checkaccess($dblink,$_SESSION['username'],$_SESSION['password'])==false){
$message='Incorrect username or password, please try again.';
echo loginform($message);
exit;
}
}
function checkaccess($dblink='', $username,$password){
if(empty($username)||empty($password)) return false;
$tmpuser=new user();
$tmpuser->id=$username;
if($tmpuser->get_user($dblink)){
$password = createpassword($password);
if($password===$tmpuser->pass){
return true;
}
$_SESSION['email']=$tmpuser->email;
unset($tmpuser);
}
return false;
}
function loginform($message=''){
unset($_SESSION['username']);
unset($_SESSION['password']);
$_SESSION = array();
session_destroy();
$secureurl=SADMINURL;
$securelink='';
if(empty($secureurl)==false && ($_SERVER['SERVER_PORT']!=443)){
$securelink='<a href="'.$secureurl.'home.php" class="menuitem">Click here for Secure Login ></a>';
}
$field='<html>
<head>
<title>Login</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body marginwidth="0" leftmargin="0" topmargin="0" marginheight="0">
<center>
<form action="'.$_SERVER['PHP_SELF'].'" name="login" method="post">
<input type="hidden" name="form" value="login">
<table border="0" width="800" cellspacing="0" cellpadding="2" style="border: 1px solid black;">
<tr><td colspan="2">'.create_header().'</td></tr>
<tr><td colspan="2" height="150">'.$message.'</td></tr>
<tr><td align="right" width="40%">User:</td><td align="left" width="60%"><input type="text" name="lusername" value=""></td></tr>
<tr><td align="right">Password:</td><td align="left"><input type="password" name="lpassword" value=""></td></tr>
<tr><td> </td><td align="left"><input type="submit" name="submit" value="Login"> <input type="reset" name="reset" value="Reset"><br /><br />'.$securelink.'</td></tr>
<tr><td height="200" valign="bottom" align="center" colspan="2">'.
'<div class="smalllight">Powered By: <a class="menuitem" href="'.ABOUT_URL.'" target="_blank">'.ABOUT_COMPANY.'</a><br />'.
ABOUT_COPYRIGHT.'</div>'.'
</td></tr>
</table>
</form>
</center>
</body>
</html>';
return $field;
}
?>
i usually use put this in it's own file, then i include it on every page i want to restrict access to.