httpauth03.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:01 2007 from httpauth03.php 2006/03/06 1.5 KB bytes.

<?php
// third try httpauth03.php
// set USER and PASSWORD
$auser = 'user3';
$apass = 'pass3';

function auth_user() {
 $realm = mt_rand( 1, 1000000000 );
 header('WWW-Authenticate: Basic realm="Realm ID='.$realm.']"');
 header('HTTP/1.0 401 Unauthorized');
 if (isset($_GET['action']) && $_GET['action'] == "logout") {
   die("<p>You are now logged out. <b>Close browser!</b></p>");
 } else {
   die("<p><b>Unauthorized access is forbidden!</b></p>");
 }
}

if (!isset($_SERVER['PHP_AUTH_USER'])) {
 auth_user();
} else if (!isset($_SERVER['PHP_AUTH_PW'])) {
 auth_user();
} else if ($_SERVER['PHP_AUTH_USER'] != $auser || $_SERVER['PHP_AUTH_PW'] != $apass) {
 auth_user();
} else if (isset($_GET['action']) && $_GET['action'] == "logout") {
 auth_user();
}
// Normal Page HTML goes below here
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Zip File Listing</title>
</head>
<body>
<h1 align="center">Zip File Listing</h1>

<?php
echo "<p>Hi ".$_SERVER['PHP_AUTH_USER'].". You are now logged in ...</p>";
?>

<p>List of files available for download is as follows ...</p>

<ul>
<li>Item 1 ...
<li>Item 2 ...
<li>Item 3 ...
</ul>

<p>When completed, to log out, simple close the browser ... or click 
<a href="httpauth03.php?action=logout">logout</a> ... and click Cancel
in the Authentication dialog, then <b>CLOSE BROWSER</b>.</p>

</body>
</html>

index

Valid HTML 4.01 Transitional