Well I was looking at my login script and thinking that I could probably write a more efficient version, but I'm not really sure how to go about doing so.
For the moment $stat is either 0 or 1, 0 representing enables and 1 disabled. In the future I hope to make it a bit coded value, that could perhaps contain the typeid (The typeid representing various user levels. For this particular section (admin) only admin users may log in.)
(I have no idea how to handle a bit coded value, if anyone knows of any good tutorials, or has a good idea please post that too.)
I will look into better security, such as md5 the password when I get the basics sorted out 😉
Anyway this is how it goes, the rest is fairly self explanatory.
<?php
error_reporting (E_ALL ^ E_NOTICE);
include ("lib/config.php");
session_start();
$handle = fopen ($usersDB,"rb");
while ($items = fscanf ($handle, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]\n")) {
list ($id, $stat, $typeid, $user, $pass, $description) = $items;
if ($_POST["username"] == $user) {
if ($_POST["password"] == $pass) {
if ($stat != 1) {
if ($typeid == 1) {
$_SESSION["login"] = "true";
header("Location:index.php");
exit;
} else {
$_SESSION["error"] = "<p style=\"color:red;\">The user specified does not have admin rights.</p>";
header("Location:loginform.php");
fclose ($handle);
exit;
}
} else {
$_SESSION["error"] = "<p style=\"color:red;\">The user account specified has been dissabled.</p>";
header("Location:loginform.php");
fclose ($handle);
exit;
}
} else {
$_SESSION["error"] = "<p style=\"color:red;\">The password specified was incorrect.</p>";
header("Location:loginform.php");
fclose ($handle);
exit;
}
}
}
$_SESSION["error"] = "<p style=\"color:red;\">The user name specified was not found on the server.</p>";
header("Location:loginform.php");
fclose ($handle);
?>
Thanks for taking a lok 😉
I know I posted this in the wrong forum, if I could move it to coding I would, sorry.