Here is a little something you can do. Something like this took me about 5 minutes to code and it even checks to see if the account has been disabled in the database.
<?php
session_start(); //Start the session
//Set username and password in $uid and $pwd if its found in $_POST or $_SESSION.
if (isset($_POST['uid'])) {
$uid = $_POST['uid'];
} else {
$uid = $_SESSION['uid'];
}
if (isset($_POST['pwd'])) {
$pwd = $_POST['pwd'];
} else {
$pwd = $_SESSION['pwd'];
}
//If uid is not set, show the login form.
if(!isset($uid)) {
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Please Log In for Access </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Login Required </h1>
<p><form method="post" action="<?=$_SERVER['PHP_SELF']?>">
User ID: <input type="text" name="uid" size="8" /><br />
Password: <input type="password" name="pwd" SIZE="8" /><br />
<input type="submit" value="Log in" />
</form></p>
</body>
</html>
<?php
exit;
}
//Set the session array variables.
$_SESSION['uid'] = $uid;
$_SESSION['pwd'] = $pwd;
//Check the database against provided credentials.
$sql = "SELECT * FROM in_users WHERE
user_name = '$uid' AND password = '$pwd'";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred while checking your '.
'login details.\\nIfhis error persists, please '.
'contact dsfsdgghas.');
}
if (mysql_num_rows($result) == 0) {
unset($_SESSION['uid']);
unset($_SESSION['pwd']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Access Denied </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Access Denied </h1>
<p><form method="post" action="<?=$_SERVER['PHP_SELF']?>">
User ID: <input type="text" name="uid" size="8" /><br />
Password: <input type="password" name="pwd" SIZE="8" /><br />
<input type="submit" value="Log in" />
</form></p>
</body>
</html>
<?php
exit;
}
//Check if account is active. 0 is no 1 is yes.
if (mysql_result($result,0,'active') == 0){
echo 'Your account is currently disabled. Please contact <a href="mailto:sdgsdfgdfg">Kyle</a> to reinstate your account.';
exit;
}
//set the users access level in the $ac_lvl variable to later be called by the script.
$ac_lvl = mysql_result($result,0,'ac_lvl');
//Set the user name for use of "Logged in as ..."
$username = mysql_result($result,0,'user_name');
?>
Then later in the script you can call the variable...
//Call the access variable to confirm they have proper access to the page.
if ($ac_lvl != 2 ){
//Deny access to page.
exit;
}
Hope this helps!