Re: using Flat File

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux