Help on a PHP Login Script?

aqua

New member
Yes, it seems I can not get this script to go through correctly. See, I am using a free host website and they allow PHP but they do not allow MySQL so I have been saving my data in a text file. (*.txt) My register or sign up script works perfectly, taking the needed Information and putting it into a text field. After so it sends you to the login stating your account has been made. I look into the server and it is all created correctly. Now I go to sign in and thus the problems begin. I am trying to save the data into a cookie. Here is the script:

<?php
$username = strtolower($_POST['username']);
$password = $_POST['password'];
$age = $_POST['age'];
$continue = "false";
if(!file_exists("users/" . $username . ".txt")) {
header("Location: login.php?error=exist");
} else {
$filename = "users/" + $username + ".txt";
$file = fopen($filename, "w");
$continue = "true";
}
if($continue == "true") {
while(!feof($file))
{
if(fgets($file) == $password)
{
Login('true');
}
}
fclose($file);
}
if($continue == "false") {
header("Location: login.php?error=exist");
}
function Login($tf) {
if($tf !== 'true') {
$tf = 'false';
}
if($tf == 'true') {
$name = $username;
$value = 'loggedIn';
$expire = time()+86400;
setcookie($name, $value, $expire);
header("Location: /home.htm");
}
if($tf == 'false') {
header("Location: login.php?error=unknown");
}
}
?>


If you look at it, all the links listed with ?error= they all lead back to the login page with an error message generated by the appropriate error key. error code exist comes back with account name already taken. What we did is took the username they entered and just made a file with the username. Say if you were to sign up with these settings:

Username: Shirley
Password: abc
Age 56

It would save a file on the server named "shirley.txt" and write:

shirley
abc
56

into the file. We can detect if the name is taken by seeing is the file user/shirley.txt exist.
ANYWAYS I am getting of topic. Can anyone see why this code is not working? I have been pushing PHP off for a long time now, but when I come up empty handed, I am trying to learn it. It actually isn't that complicated, despite my problems. x3 I know quite a lot of HTML, CSS, and JavaScript. But only a little PHP so I would appreciate the help. If you need any more details, just ask!
 
Back
Top