Saj
05-22-2003, 02:02 PM
Hi.
I am creating a simple login script which doesn't use MySQL or a text file basicly because what I need to use is too simple to waste a MySQL database on. Anyway, here is the code:
$user = $_POST["user"];
$pass = $_POST["pass"];
if (!$submit) {
echo "<form action=\"admin.php\" method=\"post\">
<input type=\"text\" size=\"20\" maxlength=\"19\" name=\"user\" />
<input type=\"password\" size=\"20\" maxlength=\"19\" name=\"pass\" />
<input type=\"submit\" maxlength=\"19\" value=\"Submit\" name=\"submit\" />
</form>";
}
else {
if ($user != "admin" || $pass != "password" ) {
echo "Error! Incorrect Username or Password!
<form action=\"admin.php\" method=\"post\">
input type=\"text\" size=\"20\" maxlength=\"19\" name=\"user\" />
<input type=\"password\" size=\"20\" maxlength=\"19\" name=\"pass\" />
<input type=\"submit\" maxlength=\"19\" value=\"Submit\" name=\"submit\" />
</form>";
}
else {
echo "Login successful<br /> <a href=\"admin.php?page=test\">Test Page</a>";
}
}
if ($page == "test" ) {
echo "This is the test page";
}
Basicly it prints a form, if the login is incorrect, it adds an error message, but if you get it correct, it moves to another page, admin.php?page=test. However, when I go to that page, the login page comes back up again because I "have not submitted" Is there a way to overcome this?
Thanks
I am creating a simple login script which doesn't use MySQL or a text file basicly because what I need to use is too simple to waste a MySQL database on. Anyway, here is the code:
$user = $_POST["user"];
$pass = $_POST["pass"];
if (!$submit) {
echo "<form action=\"admin.php\" method=\"post\">
<input type=\"text\" size=\"20\" maxlength=\"19\" name=\"user\" />
<input type=\"password\" size=\"20\" maxlength=\"19\" name=\"pass\" />
<input type=\"submit\" maxlength=\"19\" value=\"Submit\" name=\"submit\" />
</form>";
}
else {
if ($user != "admin" || $pass != "password" ) {
echo "Error! Incorrect Username or Password!
<form action=\"admin.php\" method=\"post\">
input type=\"text\" size=\"20\" maxlength=\"19\" name=\"user\" />
<input type=\"password\" size=\"20\" maxlength=\"19\" name=\"pass\" />
<input type=\"submit\" maxlength=\"19\" value=\"Submit\" name=\"submit\" />
</form>";
}
else {
echo "Login successful<br /> <a href=\"admin.php?page=test\">Test Page</a>";
}
}
if ($page == "test" ) {
echo "This is the test page";
}
Basicly it prints a form, if the login is incorrect, it adds an error message, but if you get it correct, it moves to another page, admin.php?page=test. However, when I go to that page, the login page comes back up again because I "have not submitted" Is there a way to overcome this?
Thanks