Hi,
I'm really knocking my head against a wall on this one. I simply can't see anything wrong. I am attempting to write a rudimentary encrypted flat file authentication program. When passing the variables $username and $password from the form to the script that looks up the entry and sees if entry is allowed, they don't seem to be being passed. Also, when I echo the vars I get zeros appearing and it also doesn't print the text I use to id the vars:
e.g.
echo ("username:" . $username);
^
doesn't print to browser.
Basically, why isn't this working? I've also tried sending them via get and using hidden fields and it won't work....
Excuse the length of the code.
login.php
<HEAD>
</HEAD>
<BODY>
<!-- -->
<FORM ACTION="processlogin.php" METHOD=get>
<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">
<TR>
<TD align="center">
<br> please enter a username
<input type="text" name="username" size="10" maxlength="10">
<br> please enter a password
<input type="text" name="password" size="10" maxlength="10">
</TD>
</TR>
<TR>
<TD>
<INPUT type="submit" value="Members Login">
</TD>
</TR>
</TABLE>
<br><br><br><br>
<B> If you don't have a username and password, please
<A href="registration.html"> register here </A> </B>
</FORM>
</BODY>
processlogin.php
echo ("username: " + $username + " password: " + $password);
$auth = false;
if (isset($password) && isset($username)) {
// read the contents of the password file
$file = "password.txt";
$fp = fopen($file , 'r' );
$passfile = fread( $fp, filesize( $file ) );
fclose( $fp );
echo("filename: " + $file);
$encpassfile = explode(" ", $passfile);
foreach ( $encpassfile as $pass ) {
list( $storeduser, $storedpass ) = explode( ':', $pass );
if ( ( $storeduser == "$username" ) ) {
$salt = substr( $storedpass , 0 , 3 );
$encpassword = crypt($storedpass, $salt);
if ($storedpass == "$encpassword") {
$auth = true;
break;
}
}
if ( ! $auth ) {
echo ("username: " + $username + " password: " + $password);
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
}
else {
// header("location: file://$docroot/membersonly.php");
}
} //foreach