I recently bought a software package that restricts access to one or many directories on my hosted server. The server is unix based. The directory that is restricted contains an .htaccess file and I believe that it uses Apache. If I try to access a file within that directory, the browser pops up a username / password input box. When I add the correct username / password, I am granted access.
My goal is to NOT use the browser popup and login through my HTML home page. I was able to access this restricted directory with the following URL format, "username : password@www.domain.com/directory".
IE has added security to not allow this.
The work around is to use session cookies.
I’ve been Googling for examples and have been reading all that I can with no luck.
I’m not exactly sure what the steps are to access an HTML file in my restricted directory.
I’ve been trying to add the following code to my home page / login page and trying to access it with the form action = $PHP_SELF.
This is really becoming frustrating and I would really appreciate any examples and advice..
Thx…
<?php
function auth(
$username = '',
$password = '',
$pass_file = './cgi-bin/pa/d_pass.txt'
) {
session_start();
global $PHP_SELF, $authdata;
$check = ! empty( $username );
if ( is_array( $authdata ) ) {
return true;
} elseif ( $check ) {
$fp = fopen( $pass_file, 'r' );
while ( !feof( $fp ) ) {
$line = trim( fgets( $fp, 1000 ) );
list( $l, $p ) = explode( ',', $line );
if ( ($l == $username) && ( $p == $password) ) {
$authdata = array("login"=>$username);
session_register( 'authdata' );
fclose( $fp );
return true;
}
}
fclose( $fp );
unset( $authdata );
return false;
} else {
return false;
}
?>