Re: using Flat File

From: Date: Wed, 22 Jan 2003 21:02:19 +0000
Subject: Re: using Flat File
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-25048@lists.php.net to get a copy of this message
Check to see if $PHP_AUTH_USER exists by echoing it to the browser, and make sure you have permissions to the txt file you are trying to read. That's all I can think of given the lack of information such as error messages, where it breaks, etc. web man wrote:
Hi, I have posted my question to this list before but I did not get a help that I was expected. All I wanted to do is to give access for the users to view a page in which the below code is embedded. The user will enter his/her username and password. But the code is not working. I don't know what to think. I need your help guys. Don't let me die on this code $auth = false; if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { $filename = 'c:\\php_data\\file.txt'; $f = @fopen($filename, "r");
    if ($f != FALSE)
    {    $a = @fread($f, filesize($filename));
           fclose($f);
    }
    else
    {
         echo "Could not open file";
    }
$lines = explode ( "\n", $file_contents ); foreach ( $lines as $line ) {
       list( $username, $password ) = explode( ':', $line );
       if ( ( $username == "$PHP_AUTH_USER" ) &&
            ( $password == "$PHP_AUTH_PW" ) ) {
           $auth = true;
           break;
       }
} } if ( ! $auth ) { header( 'WWW-Authenticate: Basic realm="Private"' ); header( 'HTTP/1.0 401 Unauthorized' ); echo 'Authorization Required.'; exit; } else { echo ' You are authorized! '; } ?> --------------------------------- Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now
-- John Krewson Programmer - SWORPS

« previous php.db (#25048) next »