"; } else { echo "
"; } exit; } if( isset( $_GET['logout'] ) ) { session_destroy(); header('Location: ' . $_SERVER['PHP_SELF'] . '?' . urldecode($_GET['logout'])); exit; } if( !isset( $_SESSION['login'] ) || isset($_GET['donotuse401']) || isset($_POST['donotuse401'])) { if ((!isset($_SERVER["PHP_AUTH_USER"]) || isset($_GET['donotuse401']) || isset($_POST['donotuse401'])) && ($_GET['donotuse401'] != "form" && $_POST['donotuse401'] != "form")) { if (isset($_GET['use401'])) { header("WWW-authenticate: basic realm=\"authorized usage\""); header("HTTP/1.0 401 Unauthorized"); echo "You're username/password is incorrect ..."; exit; } else { $msg="Please log in here:"; if ($_GET['donotuse401'] == "Error") $msg="Cannot reach database. Please log in here:"; if ($_GET['donotuse401'] == "error") $msg="Wrong username/password. Please log in here:"; if ($_POST['donotuse401'] == "Error") $msg="Cannot reach database. Please log in here:"; if ($_POST['donotuse401'] == "error") $msg="Wrong username/password. Please log in here:"; if (isset($_GET["backto"])) { $backtostr=''; } else if (isset($_POST["backto"])) { $backtostr=''; } echo '
' . $backtostr . '
' . $msg . '
Username:
Password:
'; exit; } } else { // check out the MySql database include "db_connect.php"; try { $link = db_connect(); if (!$link) { if (isset($_GET['donotuse401']) || isset($_POST['donotuse401']) || !isset($_SERVER["PHP_AUTH_USER"])) { echo "
"; exit; } else { die('Could not connect: ' . mysql_error()); } } mysql_select_db("users"); } catch (Exception $e) { if (isset($_GET['donotuse401']) || isset($_POST['donotuse401']) || !isset($_SERVER["PHP_AUTH_USER"])) { echo "
"; exit; } else { die('Could not connect: ' . mysql_error()); } } if (isset($_POST['username'])) { $username=strtolower(urldecode($_POST['username'])); } else { $username=strtolower($_SERVER["PHP_AUTH_USER"]); } $result=mysql_query("SELECT password FROM users WHERE username='" . $username . "'"); $row=mysql_fetch_array($result); if (isset($_POST['username'])) { if (urldecode($_POST['password']) != $row["password"]) { echo "
"; exit; } } else { if ($_SERVER["PHP_AUTH_PW"] != $row["password"]) { header("WWW-authenticate: basic realm=\"authorized usage\""); header("HTTP/1.0 401 Unauthorized"); echo "You're username/password is wrong ..."; exit; } } $_SESSION['login']=true; } } if (!isset($_SERVER["PHP_AUTH_USER"]) && isset($_GET['use401'])) { header("WWW-authenticate: basic realm=\"authorized usage\""); header("HTTP/1.0 401 Unauthorized"); echo "You're username/password is incorrect ..."; exit; } if (isset($_GET["backto"])) { $nextpage=$_GET["backto"]; $nextvals=explode("/", $nextpage); $nextval= strtoupper(substr($nextvals[sizeof($nextvals) - 1],0,1)) . str_replace(".php", " Page", substr($nextvals[sizeof($nextvals) - 1],1)); $backtoonload=' onload=" document.getElementById(' . "'" . 'subm' . "'" . ').click(); "'; } else if (isset($_POST["backto"])) { $nextpage=$_POST["backto"]; $nextvals=explode("/", $nextpage); $nextval= strtoupper(substr($nextvals[sizeof($nextvals) - 1],0,1)) . str_replace(".php", " Page", substr($nextvals[sizeof($nextvals) - 1],1)); $backtoonload=' onload=" document.getElementById(' . "'" . 'subm' . "'" . ').click(); "'; } if (!file_exists("loginpage.name")) { file_put_contents("loginpage.name", $_SERVER['PHP_SELF']); } ?> >


Logout