Results 1 to 12 of 12

Thread: php login

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    php login

    hi guys, how do I make a php login page, i dont need the usernames and passwords to be verified by a database, I just want to verift the username and pass right from the php code, how would i do this? if this isn't fairly easy, please send me in the right direction

    thanks

    ~~~Dimava~~~
    NXSupport - Your one-stop source for computer help

  2. #2
    scoutt
    Guest
    well if you don't use a database and you put the password and user ID in the script it won't be very secure.
    you can do it by cookies and check against a database or you can have a file with emails and passwords and it checks agains that, but it still is like a database.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    so how would i make a file? i have never worked with php before

    ~~~dimava~~~
    NXSupport - Your one-stop source for computer help

  4. #4
    scoutt
    Guest
    do you want to ba able to add the user to it or are you going to have fixed addresses in there?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I want to be able to add the user, i just want a login page, and if the username/pass is correct, then proceed onto the next page (which is the same for all users). I am going to have about 100 users.

    ~~~Dimava~~~
    NXSupport - Your one-stop source for computer help

  6. #6
    scoutt
    Guest
    ok sorry it took so long, but here it is.
    Code:
    <?php 
    
    $auth = false; // Assume user is not authenticated 
    
    if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { 
    
        // Read the entire file into the variable $file_contents 
    
        $filename = '/path/to/file.txt'; 
        $fp = fopen( $filename, 'r' ); 
        $file_contents = fread( $fp, filesize( $filename ) ); 
        fclose( $fp ); 
    
        // Place the individual lines from the file contents into an array. 
    
        $lines = explode ( "\n", $file_contents ); 
    
        // Split each of the lines into a username and a password pair 
        // and attempt to match them to $PHP_AUTH_USER and $PHP_AUTH_PW. 
    
        foreach ( $lines as $line ) { 
    
            list( $username, $password ) = explode( ':', $line ); 
    
            if ( ( $username == "$PHP_AUTH_USER" ) && 
                 ( $password == "$PHP_AUTH_PW" ) ) { 
    
                // A match is found, meaning the user is authenticated. 
                // Stop the search. 
    
                $auth = true; 
                break; 
    
            } 
        } 
    
    } 
    
    if ( ! $auth ) { 
    
        header( 'WWW-Authenticate: Basic realm="Private"' ); 
        header( 'HTTP/1.0 401 Unauthorized' ); 
        echo 'Authorization Required.'; 
        exit; 
    
    } else { 
    
        header( 'Location: http://www.yourserver.com/new_page.html' ); 
    } 
    
    ?>
    ok your password file is (file.txt) and change teh header location to what ever page you want the redirection to go to if their password checks out.

    let me know if you need help and hope it works for ya.

  7. #7
    scoutt
    Guest
    oh ya I forgot the file.txt has to be like this

    joe:ai890d
    jane:29hj0jk
    mary:fsSS92
    bob:2NNg8ed
    dilbert:a76zFs

    to whatever you like. but in that format

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks for the code, one more question... how/where do I put the username and password text boxes? and i am getting errors on these lines:
    PHP Code:
        header'WWW-Authenticate: Basic realm="Private"' ); 
        
    header'HTTP/1.0 401 Unauthorized' ); 
        echo 
    'Authorization Required.'
    thanks,

    Dimava
    NXSupport - Your one-stop source for computer help

  9. #9
    scoutt
    Guest
    Well, it should have brought up the text boxes automatically. let me play around with it and find out. I will get back with ya

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, thanks
    NXSupport - Your one-stop source for computer help

  11. #11
    scoutt
    Guest
    sorry it has taken so long, but I can't seem to find out why it don't work. I have played around with it and I keep getting 500 errors. if you want to look I got the file from Zend.com

    this might work better for ya.

    http://www.zend.com/codex.php?id=168&single=1

    also you can search around that site for more. I just have to say all teh code I get from there I can''t seem to get to work. like the one i got for you. oh wel you can try I guess.

    sorry I couldn't help any further, that has me stumped as well, I will play around with it more

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Thumbs up

    thanks, the example on the website works great

    ~~~Dimava~~~
    NXSupport - Your one-stop source for computer help

Posting Permissions

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



Click Here to Expand Forum to Full Width