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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php