Hi all,
I have the following problem. I wrote some code including a php script that is supposed to compare user input with the content of a file. Specifically, the user enters an user id and submits it, the php script opens a provided file and compares the id submitted by the user to all ids contained in the file. If the script finds a match, it will grant access to the user. Below is the code I wrote. For some reason it won't work for me. Any help or advice is highly appreciated.
Thanks,
Tiff
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<?php
extract( $_POST );
if ( !$inputbox ) {
fieldsBlank();
die();
}
$file = fopen( "idnumbers.txt", "r" ) or die("Could not open file");
$wVerified = 0;
while ( !feof( $file ) && !$wVerified ) {
// read line from file
$line = fgets( $file, 255 );
if ( checkID( $inputbox, $line )
== true )
accessGranted( $inputbox );
else
invalidWNumber();
}
}
// close text file
fclose( $file );
}
// verify user password and return a boolean
function checkID( $inputbox, $filedata )
{
if ( $inputbox == $filedata[ 1 ] )
return true;
else
return false;
}
// print a message indicating access has been denied
function accessDenied()
{
print( "<title>Access Denied</title></head>
<body style = \"font-family: arial;
font-size: 1em; color: red\">
<strong>
You were denied access to this server.
<br /></strong>" );
}
// print a message indicating that fields
// have been left blank
function fieldsBlank()
{
print( "<title>Access Denied</title></head>
<body style = \"font-family: arial;
font-size: 1em; color: red\">
<strong>
Please fill in all form fields.
<br /></strong>" );
}
?>
</body>
</html>
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Verify ID</title>
</head>
<body>
<form name="enterID" action="IDnumber.php" method="post">
Please enter your ID-number below: <BR />
<input type="text" name="inputbox" id="inputbox" maxlength="8"/>
<input type="submit" name="submit" id="submit" value="Submit"/>
</form>
</body>
</html>