note 29544 deleted from function.crypt by ronabop

From: Date: Mon, 17 Feb 2003 08:23:45 +0000
Subject: note 29544 deleted from function.crypt by ronabop
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-44081@lists.php.net to get a copy of this message
Hi, Why isn't the following code working? <?php $auth = false; if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { $password = $PHP_AUTH_PW; $salt = substr( $password , 0 , 2 ); $enc_pw = crypt( $password, $salt ); $filename = 'file.htpasswd'; $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($enc_pw == $password && $username == $PHP_AUTH_USER) $auth = true; echo "$enc_pw - $password<br>"; } } 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>'; } ?> Greets, Erik.

« previous php.notes (#44081) next »