Location: PHPKode > projects > Peardrop CMS > peardrop/inc/auth.inc.php
<?php
function printForm()
{
print <<<ENDHTM
<!DOCTYPE html>
<html>
   <head>
	<link href="./css/admin_style.css" type="text/css" rel="stylesheet">
	<title>Log in to continue</title>
   </head>
	<body>
		<br><br><br><br><br>
		<div id="auth-box">
ENDHTM;

echo "<a href='" . $_SERVER['PHP_SELF'] . "'>Login</a>";

print <<<ENDHTM
		<p><strong>You must be logged in to continue</strong>
		<a href="password_reset.php">Forgot Password</a>
		</div>
		<br><br><br><br><br>
	</body>
</html>
ENDHTM;
}

function logAdmin()
{
		$log = "./config/system.log";
	$file = fopen($log, "a+");
	$size = filesize($log);

	$ip = $_SERVER['REMOTE_ADDR']; //Get there ip address.
	$date = date("[d-M-Y H:i:s]: "); //Get the date and time.
	fwrite($file, $date."Authenticated admin activity from IP [".$ip."]\n");

	$text = fread($file, $size);
	fwrite ($file, $space);
	fclose($file);
}

function logFailedLogin()
{
	$log = "./config/system.log";
	$file = fopen($log, "a+");
	$size = filesize($log);

	$ip = $_SERVER['REMOTE_ADDR']; //Get there ip address.
	$date = date("[d-M-Y H:i:s]: "); //Get the date and time.
	fwrite($file, $date."A failed login attempt had been logged from IP [".$ip."]\n");

	$text = fread($file, $size);
	fwrite ($file, $space);
	fclose($file);
}

session_start();

include('./config/passwd.inc.php');

if(isset($_GET['logout']))
{
  unset($_SESSION["login"]);
   
  echo "<h2>You are logged out... </h2>";
  printForm();
  exit;
}

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]))
{
  header("WWW-Authenticate: Basic realm=\"Peardrop Administration\"");
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  echo "<h2>You are unauthorized ... </h2>";
  printForm();
  exit;
}
else
{
  if($_SERVER['PHP_AUTH_USER'] == $username && md5($_SERVER['PHP_AUTH_PW']) == $password)
  {
    logAdmin();
    //print nothing, 
    
  }
  else
  {
    unset($_SESSION["login"]);
    logFailedLogin();
    header("Location: " . $_SERVER['PHP_SELF']);
  }
}

// content here

?>
Return current item: Peardrop CMS