Uses MySQL - you should get the idea:
<?php
//Created by Daniel Herman
//=========
//=MYSQL Details=
//=========
// The location of your Database - usually localhost
$dbServer = "localhost";
// The database username
$dbUserName = "hermand";
// The database password
$dbPassword = "";
// The database name
$dbDatabase = "hermand";
// Connect to the database.
$db = mysql_connect($dbServer, $dbUserName, $dbPassword) or die(mysql_error());
mysql_select_db($dbDatabase, $db) or die(mysql_error());
//Define variables from the submitted form (If the form hasn't been submitted, these will be blank)
$pword = $HTTP_POST_VARS['pword'];
$uname = $HTTP_POST_VARS['uname'];
//Md5 the password, encryption method - delete this line if you dont want encryption
$pword = md5($pword);
// If the username hasn't been defined, get it from the cookie
if(!$uname){
$uname = $HTTP_COOKIE_VARS['login_uname'];
$pword = $HTTP_COOKIE_VARS['login_pword'];
}else {
// Othewise (Ie if the form was submitted) add the cookie and create an error message
$error = "Could not verify password / username";
$ses_uname = $uname ;
$ses_pword = $pword;
setcookie ("login_uname", $ses_uname,time()+(3600*168));
setcookie ("login_pword", $ses_pword,time()+(3600*168));
}
// Run the query
$query = "SELECT * FROM members where uname = '$uname'
and pword = '$pword' ";
$result = mysql_query($query, $db) or die(mysql_error());
$numRows = mysql_num_rows($result);
for ($count = 0; $count < $numRows; $count++) {
$resultArray = mysql_fetch_array($result);
$cuname = $resultArray["uname"];
$cpword = $resultArray["pword"];
}
if (!$cuname){
$url = $REQUEST_URI;
?>
<form method=POST action="<?php echo $url; ?>">
<br>
<b>Please Login:</b><br>
<input name="form_action" type="hidden" value="<?php echo $action; ?>">
<br>
<table>
<tr>
<td>Username:</td><td class="shownews"><input name="uname" type="text" size="20" tabindex="1"></td>
</tr>
<tr>
<td>Password:</td><td class="shownews"><input name="pword" type="password" size="20" tabindex="2"></td>
</tr>
<tr>
<td></td><td><input type="submit" name="submit" value="Log In" tabindex="4"> <input type="reset" name="reset" value="Clear Form" tabindex="5"></td></tr>
<tr>
<td colspan="2"><b><?php echo $error ?></b></td></tr>
</table>
</form>
<?php
//Exit the file, so that the passworded page isn't displayed
exit;
}else{
echo " ";
}
?>