View Full Version : I need a WildCard in this script, but i dont know how to do it.......

Silver Sun
01-30-2003, 09: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

01-30-2003, 10: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.:)

02-02-2003, 10:50 AM

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

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";


/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
// 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..