Dentafrice,
25-09-2007, 02:24 AM
Well I have been playing around with classes lately:
I know this is not secure, it is not meant to be.
save this as your login.php:
<?php
$action = $_GET[action];
if ($action == "login") {
include "class.php";
$user = new authentication;
$user->correctu = "Caleb";
$user->correctp = "testing";
$user->success = "testing.php";
$user->username = $_POST[username];
$user->password = $_POST[password];
$user->start_login();
exit;
}
?>
<!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>Simple Login</title>
<style type="text/css">
<!--
.style1 {font-family: "Trebuchet MS", Verdana, Arial}
-->
</style>
</head>
<body>
<span class="style1"><u><strong>Simple user login</strong></u>
<br>
<br>
</span>
<form action="?action=login" method="post" name="login_form" class="style1">
<fieldset><legend>Details</legend>
<br>
<strong>Username:<br>
<label>
<input name="username" type="text" id="username" size="30">
</label>
<br>
<br>
Password:</strong>
<br>
<strong>
<input name="password" type="password" id="password" size="30">
</strong><br>
<br>
<label>
<input type="submit" name="Submit" value=" Login ">
</label>
</fieldset>
</form>
</body>
</html>
Save this as your class.php:
<?php
class authentication {
var $username;
var $password;
var $correctu;
var $correctp;
var $success;
function clean($value) {
return strip_tags(htmlspecialchars(addslashes(stripslashe s($value))));
}
function go($url) {
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\">";
}
function check_username() {
if ($this->username != $this->correctu) {
echo "Sorry, that is an incorrect username!";
exit;
}
$this->check_password();
}
function check_password() {
if ($this->password != $this->correctp) {
echo "Sorry, that password was incorrect!";
exit;
}
$this->go($this->success);
}
function start_login() {
$this->username = $this->clean($this->username);
$this->password = $this->clean($this->password);
if ($this->username == "" || $this->password == "") {
echo "Please fill in all correct fields!";
exit;
}
$this->check_username();
}
}
?>
Its just a simple thing, classes save a HUGE amount of time :)
I know this is not secure, it is not meant to be.
save this as your login.php:
<?php
$action = $_GET[action];
if ($action == "login") {
include "class.php";
$user = new authentication;
$user->correctu = "Caleb";
$user->correctp = "testing";
$user->success = "testing.php";
$user->username = $_POST[username];
$user->password = $_POST[password];
$user->start_login();
exit;
}
?>
<!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>Simple Login</title>
<style type="text/css">
<!--
.style1 {font-family: "Trebuchet MS", Verdana, Arial}
-->
</style>
</head>
<body>
<span class="style1"><u><strong>Simple user login</strong></u>
<br>
<br>
</span>
<form action="?action=login" method="post" name="login_form" class="style1">
<fieldset><legend>Details</legend>
<br>
<strong>Username:<br>
<label>
<input name="username" type="text" id="username" size="30">
</label>
<br>
<br>
Password:</strong>
<br>
<strong>
<input name="password" type="password" id="password" size="30">
</strong><br>
<br>
<label>
<input type="submit" name="Submit" value=" Login ">
</label>
</fieldset>
</form>
</body>
</html>
Save this as your class.php:
<?php
class authentication {
var $username;
var $password;
var $correctu;
var $correctp;
var $success;
function clean($value) {
return strip_tags(htmlspecialchars(addslashes(stripslashe s($value))));
}
function go($url) {
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\">";
}
function check_username() {
if ($this->username != $this->correctu) {
echo "Sorry, that is an incorrect username!";
exit;
}
$this->check_password();
}
function check_password() {
if ($this->password != $this->correctp) {
echo "Sorry, that password was incorrect!";
exit;
}
$this->go($this->success);
}
function start_login() {
$this->username = $this->clean($this->username);
$this->password = $this->clean($this->password);
if ($this->username == "" || $this->password == "") {
echo "Please fill in all correct fields!";
exit;
}
$this->check_username();
}
}
?>
Its just a simple thing, classes save a HUGE amount of time :)