If you want a php version I have one that uses sessions and redirects. It not as secure as .htaccess but should suit your needs...
this is the page you want to protect, lets say it's index.php
PHP Code:
<?php
session_start();
if ($_SESSION['ID22'] != "yes") { include 'pass.php'; }
else{
?>
<html>
<head>
<title>Members Only!</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="/css.css" />
</head>
<body>
<p> Members only content viewable here!</p>
</body>
</html>
<?php } ?>
When they go to this page, if the session doesn't match they will be shown "pass.php" which is in the same folder....
PHP Code:
<?php
session_start();
if (isset($_POST['submit'])) {
if((strtolower($_POST['user']) == "Bob") && (strtolower($_POST['pass']) == "tree")){
$_SESSION['ID22'] = 'yes';
header('Location: '.$_SERVER['HTTP_REFERER']);
}
else {
$_SESSION['CWoT22'] = 'no';
header('Location: http://yoursite.com/401.shtml');
}
}
else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Password Required To Continue!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="/css.css">
</head>
<body>
<div id="pass">
<p>Please Enter Username and Password</p>
<form action="<?=$PHP_SELF?>" method="post">
<p>Username: <input type="text" name="user"></p>
<p>Password: <input type="password" name="pass"></p>
<p><input type= "submit" name= "submit" value= "Continue!"></p>
</form>
</div>
</body>
</html>
<?php } ?>
Editing the username (bob) and password (tree) to what you need, and the http://yoursite.com/401.shtml to point to your 401 page.
Bookmarks