Right now I'm doing simple interactions with text files, before I go into MySQL databasing. I'm trying to create a very simplistic login script where the user inputs a username and password into a form, presses submit, and the variables are processed through a PHP script which checks a login.txt file for a concurring login name, and checks to see if the password associated with said login name is correct.
The code goes as follows:
Code: Select all
<?php
function LoginScript(){
$TheFile = "login.txt";
$Open = fopen($TheFile, "r");
if ($Open){
$Data = file($TheFile);
for ($n = 0; $n < count($Data); $n++){
$GetLine = explode(", ", $Dataї$n]);
$User = $_POSTї"FormUser"];
$Password = $_POSTї"FormPassword"];
if (($User) AND ($Password)){
if (ereg("$User", "$GetLineї0]")){
if (ereg($Password, $GetLineї1])){
print("<B>Debugging:</B> You typed: ");
print($User);
print("<BR><B>Debugging:</B> You needed to type: ");
print($GetLineї0]);
print("<BR>You correctly matched with our systems.");
break;
} else {
print("<B>Login failure</B>: Your login or password does not match our systems.");
break;
}
} else {
if ($n == (count($Data) - 1)){
print("<B>Login failure</B>: Your login or password does not match our systems.");
}
}
} else {
print("<B>Login failure:</B>Please enter a username and password");
break;
}
}
}
}
LoginScript();
?>Here
Use the login: PHP
Password: PHP
It works fine, you'll notice, if you put in the right password and login. It will also put out errors if you don't put the right password or login in correctly. However, if you just put "p" in for the login, and "p" for the password, it'll still go through. Why is this? It seems to be doing it letter by letter instead of entire string by entire string. Thanks if anyone can help me out.
-Wallabee[/url]