<?php
    $username 
strtolower(trim($_POST['username']));
    
$password trim($_POST['password']);
    
$USERS_K file(".htusers");
    
$PASSWORDS_K file(".htpasswords");
    
$isuser 0// Is the user in the list?
    
$isauth 0// Does the user have the correct password?
    
$ploc 0// Holds the location of the user/password in the lists

    
    
for ($x 0$x count($USERS_K); $x ++) {
        if (
$username == trim($USERS_K[$x])) {
            
$ploc $x// ploc remembers where the user is in the list
            
$x count($USERS_K);
            
$isuser 1// The user is in the list
        
}
    }
    
    
// If user is in the list, begins password verification
    
if ($isuser == 1) {
        if (
crypt($password$password) == trim($PASSWORDS_K[$ploc])) {
            
$isauth 1// User is authenticated on the network
        
}
    }
    
    if (
$isauth == 1) {
        echo 
"Insert landing page here!"//# Example: include "filename.ext";
    
}
    
    
    
//* Routines to educate the users of their errors
    
    // Claims the user was not in the list (N)o such (U)ser
    
if ($isuser == 0) {
        
header("Location: ../?err=NU");
    }
    
// Claims password is incorrect (B)ad (P)assword
    
if ($isuser == && $isauth == 0) {
        
header("Location: ../?err=BP");
    }
?>