Alex Piotto
12-03-2002, 11:34 AM
Hi forum friends!
I am trying to build a login script for multiple users.
The code below only works with the last entry in the flat db... why? :(
flat db example:
joe;888
mark;444
mario;222
Alex;111 (only works with this entry....)
login script (preceeded by a common html form):
<?php
$auth = false; // Assume user is not authenticated
if (isset($visitor) && isset($passcode)) {
// Read the entire file into the variable $file_contents
$filename = 'C:\Xitami\webpages\testprotect\tabu\usrspwds.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
// Place the individual lines from the file contents into an array.
$lines = explode ("\n", $file_contents);
// Split each of the lines into a username and a password pair and attempt to match them.
foreach ( $lines as $line ) {
list($username, $password) = explode( ';', $line );
if ( ($username == $visitor) && ($password == $passcode) ) {
// A match is found, meaning the user is authenticated. Stop search.
$auth = true;
break;
}
}
}
if (!$auth) {
echo "Authorization Required.";
exit;
}
else {
echo "<P>You are Authorized!</P>";
}
?>
any help will be really appreciated... I am stuck on this...
thanks
:)
Alex
I am trying to build a login script for multiple users.
The code below only works with the last entry in the flat db... why? :(
flat db example:
joe;888
mark;444
mario;222
Alex;111 (only works with this entry....)
login script (preceeded by a common html form):
<?php
$auth = false; // Assume user is not authenticated
if (isset($visitor) && isset($passcode)) {
// Read the entire file into the variable $file_contents
$filename = 'C:\Xitami\webpages\testprotect\tabu\usrspwds.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
// Place the individual lines from the file contents into an array.
$lines = explode ("\n", $file_contents);
// Split each of the lines into a username and a password pair and attempt to match them.
foreach ( $lines as $line ) {
list($username, $password) = explode( ';', $line );
if ( ($username == $visitor) && ($password == $passcode) ) {
// A match is found, meaning the user is authenticated. Stop search.
$auth = true;
break;
}
}
}
if (!$auth) {
echo "Authorization Required.";
exit;
}
else {
echo "<P>You are Authorized!</P>";
}
?>
any help will be really appreciated... I am stuck on this...
thanks
:)
Alex