<?php
class admin
{
public function __construct($loggedin,$username,$password,$capchta)
{
session_start();
$this->loadHeader();
$this->hasLoggedIn($loggedin,$username,$password,$capchta);
}
public function __set($username, $_POST['username'])
{
$this->$username = $_POST['username'];
}
public function __destruct()
{
echo '</div>
</body>
</html>';
}
public function loadHeader()
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin panel</title>
<link rel="icon" href="../images/site/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../images/site/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/includes/css/adm.css" />
</head>
<body>
<div id="content">
<?php
}
private function hasLoggedIn($loggedin,$username,$password,$capchta)
{
if($this->loggedin == false)
{
$this->checkLogDetails($username,$password,$capchta);
}
else
{echo "<p>you are logged in, redirecting you to menu now...</p>MENU!!!";}
}
private function checkLogDetails($username,$password,$capchta)
{
echo "checkLogDetails reached\n";
$this->areDetailsSet($username,$password,$capchta);
#$this->sanatise();
#stripslashes();
#$this->checkdb();
}
private function areDetailsSet($username,$password,$capchta)
{
echo "areDetailsSet reached\n";
if(!isset($this->username) || !isset($this->password))
{
$this->loadLoginForm("Both fields need to be filled");
exit;
}
else
{
$this->doesCaptchaMatch($capchta);
}
}
private function doesCaptchaMatch($capchta)
{
echo "doesCaptchaMatch reached\n";
$securimage = new Securimage();
if ($securimage->check($this->capchta) == false)
{
echo "doesCaptchaMatch Loop reached\n";
$this->loadLoginForm("The captch acode you entered was incorrect.");
}
}
private function sanatise($username ,$password)
{
if(!ctype_alnum($username) || !ctype_alnum($password))
{
$this->loadLoginForm("<p>Invalid characters used in username or password</p>");
$_SESSION['loggedin'] == false;
}
elseif(checkLengh($username ,$password) == false)
{
loadLoginForm("<p>Login details too long or too short</p>");
$_SESSION['loggedin'] == false;
}
}
private function checkLengh($username,$password)
{
if(strlen($username) > 20 || strlen($password) > 20 || strlen($username) < 8 || strlen($password) < 8)
{
return false;
}
}
public function loadLoginForm($error)
{
echo'<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="log" >';
if(isset($error))
{
echo $this->error;
}
$this->loadLogfields();
$this->LoadCaptcha();
echo '</form>';
}
private function loadLogfields()
{
?>
<fieldset>
<legend>Login</legend>
<label for="nam">Username: </label><input type="text" id="nam" name="username" value="<?php if(isset($_POST['username'])){echo $_POST['username'];} ?>" />
<label for="pas">Password: </label><input type="password" id="pas" name="password" value="<?php if(isset($_POST['password'])){echo $_POST['password'];} ?>" />
</fieldset>
<?php
}
private function LoadCaptcha()
{
?>
<fieldset>
<legend>Capcha And Submit</legend>
<p>Please enter the string as you see it.</p>
<label for="captcha_code">Capcha: </label><input type="text" name="captcha_code" size="10" maxlength="6" />
<img id="captcha" src="/includes/securephpcapchta/securimage_show.php" alt="CAPTCHA Image" /><br />
<a href="#" onclick="document.getElementById('captcha').src = '/includes/securephpcapchta/securimage_show.php?' + Math.random(); return false">Reload Image</a>
<input type="submit" value="Submit" />
</fieldset>
<?php
}
}
?>