Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Im no expert but:

    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.

  • #3
    Registered User
    Join Date
    Feb 2003
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    if (file_exists(#)){#}
    First list all files in directory:
    Code:
    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!

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •