Silver Sun
01-30-2003, 08:56 PM
You see, I have a system whereby a user logs in using a text file named $user $password .txt
Now the problem comes when multiple users sign up with the same username.
What i need is if (file_exists($file)) when $file is: $user * .txt and the * represents anything that comes between $user and .txt
Thanks in advance
missing-score
01-30-2003, 09:34 PM
I may be no expert but (assuming that I have interpreted it right) there is an easier way.
If you create text files with the persons username, and put the username and password within that file, you could then preform a test on a form to check if the username exists, then use fopen to open the text file.
I think this would work.
If you have access to My SQL you would do better.:)
Hey
I understand what you are saying, but I would suggest preventing from people signing up with a username that already exists. Method 1 is easier, but if you have no password, use Method 2.
Method 1: Since you have the password that the user entered, just pass the variable through to the script and then
file_exists("$user$pass.txt")
Method 2: Instead of
if (file_exists(#)){#}
First list all files in directory:
if ($handle = opendir('/path/to/files')) {
while (false !== ($file = readdir($handle)))
$a = $a + 1;
$filelist[$a] = "$file|null\n";
}
closedir($handle);
}
/path/to/files Points to the directory to list.. Do Not enter any filename here, just the path.
Now you have all files in list. Just search through the file to see if the username exists!
for ($num = 0; $num < count($filelist); $num++){
$values = explode("|",$filelist[$num]);
if ($values[$num] == "$user"){
// Do whatever here
exit;
// or return;
}
}
// If user is found... The script will do whatever and then exit. If it doesn't, the script should execute this:
echo "No user found.";
Of course you can modify the script to do what you want it to do.
Hope it helps..
Jesh