Yes, I have a register code and a login code. I have no access to a database on my free server so I save all of echo users data on their own file each line of the file is a different category with this current format:

username
password
age

Register works as suppose to. But the login script at the end of this post -ALWAYS- returns to the login.php screen with the error "incorrect" - input.php?error=incorrect. Can someone see why? All the information entered is correct yet it never makes it to the login function. Below are the error codes:

?error=exist | Account does not exist.
?error=unknown | Unknown error has occurred.
?error=incorrect | Incorrect password or username.

I believe I know the reason, but I can't solve it. I use $all_lines($path, "r") to turn all the lines of the file into an array. I can add $all_lines[1] to get the second line, the password as I need, but the problem there is seeing if the password is the same as the password entered on login. It always returns false as well as for if (like right now) I just put in_array for the array I have to take out the number so I have the whole array, but if I echo $all_lines it comes back as "Arrays". Could it be it is trying to see if the password equals "Arrays"?

-----------------------------------------------------------------------------------

<?php
$rawusername = $_POST['username'];
$rawpassword = $_POST['password'];
$username = strtolower($rawusername);
$password = strtolower($rawpassword);
$tf = "false";
$exist = "false";
$path = "users/" . $username . ".txt";
$file = fopen($path, "r");
$all_lines = file($path);
if(!isset($_POST['username'])) { header("Location: login.php?error=unknown"); }
if(!file_exists($path)) { header("Location: login.php?error=exist"); }
if(file_exists($path)) { $exist = "true"; }
if($exist == "false") { header("Location: login.php?error=exist"); }
if($exist == "true")
{
if(in_array($password, $all_lines))
{
$tf = "true";
Login();
} else {
header("Location: login.php?error=incorrect");
}
}
function Login()
{
if($tf == "false")
{
if(!file_exists($path))
{
header("Location: login.php?error=exist");
} else {
header("Location: login.php?error=unknown");
}
}
if($tf == "true")
{
$name = $username;
$value = 'loggedIn';
$expire = time()+86400;
setcookie($name, $value, $expire);
header("Location: /home.htm");
}
}
?>