http
Posted: Sun Jan 19, 2003 8:56 am
Hi Guys,
Please can anyone tell me why this
code is not working for me??
I have got some usernames and passwords in file.txt
but the fopen is not reading it.
Can anyone help me out here??
Thanks
Please can anyone tell me why this
code is not working for me??
I have got some usernames and passwords in file.txt
but the fopen is not reading it.
Can anyone help me out here??
Thanks
Code: Select all
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
$filename = 'c:\\inetpub\\wwwroot\\http_cookie\\file.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
$lines = explode ( "\n", $file_contents );
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 {
echo '<P>You are authorized!</P>';
}
?>