Hello,
I've a user interface where i would like to check for ip-address and password instead of the standard username and password authentication using a flat file.
I've stored the ip-address and password as follows in the text file:
123456789123:success
and my textbox field for ip-address looks like 4 boxes where the user can input only 3 digits.
If the ip-address is matched to the password, i want to print a message else a different message.
This is the code i've so far, could somebody please help me.How should i modify my exsisting code.
Many many thanks
<?php
// Assume user is not authenticated
$auth = false;
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Read the entire file into the variable $file_contents
$filename = 'licences.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 to $PHP_AUTH_USER and $PHP_AUTH_PW.
foreach ( $lines as $line ) {
list( $username, $password ) = explode( ':', $line );
if ( ( $username == "$PHP_AUTH_USER" ) &&
( $password == "$PHP_AUTH_PW" ) ) {
// A match is found, meaning the user is authenticated.
// Stop the search.
$auth = true;
break;
}
}
}
?>
<form method="post">
<table bgcolor="#E0E0E0" width="320">
<tr>
<td>
Ip address
</td>
<td align="right">
<input size="3" tabindex="1" name="myInput" maxlength="3" onkeyup="toUnicode(this,this.value)">.
<input size="3" tabindex="2" name="mySecond" maxlength="3" onkeyup="toUnicode(this,this.value)">.
<input size="3" tabindex="3" name="myThird" maxlength="3" onkeyup="toUnicode(this,this.value)">.
<input size="3" tabindex="4" name="myFourth" maxlength="3" onkeyup="toUnicode(this,this.value)">
</td>
</tr>
<tr>
<td>
Password
</td>
<td align="right"><input type="password" name="sess_pass_f" maxlength="255" size="28"></td>
</tr>
</table>
<div align="center">
<br>
<table>
<tr>
<td>
<input type="submit" value="Log in" style="position: relative; width: 150;"></td>
</form>
</table>