www.webdeveloper.com
Results 1 to 4 of 4

Thread: Login script/ arrays for names and pswords

  1. #1
    Join Date
    Jan 2004
    Posts
    2,422

    Login script/ arrays for names and pswords

    Would it be possible to make 2 arrays so that i could check if a name and password match?

    By this i mean having one array holding the names, for example foo and bar

    and then the second array holding ex1 example2

    and then sum1 puts foo as the name and ex1 as the password, id check to see if the they matched each other then what i wanted to happen could happen?

    also, could it draw the names from a .txt file?

    sorry if i was unclear. if this requires excessive work, nevermind, im just making the script for sumtin i may or may not do.

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You'd set up your two arrays, first.

    PHP Code:
    $users = array("Jon","Darryn","Pamela","Anne");
    $passwords = array("kluck","eggs","pants","wine"); 
    Then you can loop through them to see if the inputted ones are correct. Assuming you've already set variables to the $_POST formdata values...

    PHP Code:
    for($u=0$u<count($users); $u++)
      {
      if(
    $username == $user[$u] && $password == $passwords[$u]){
      
    # user/pass correct
     
    } else {
      
    # user/pass incorrect
     
    }

    To write to a file, you must first open it (fopen()), then select what you want to do with it--append ('a'), append and read ('a+'), read ('r'), read and write ('r+'), write ('w'), or write and read ('w+'). After you decide that, you can manipulate it with functions such as fread() and fwrite(). Be sure to close it with fclose() when you're done!

    [J]ona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    Jan 2004
    Posts
    2,422
    Thanks, Jona. So that's how to do arrays... when I tried to learn them php.net ranted on about key values and I was lost.

    Much thanks.

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Happy to help!

    [J]ona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles