I have My code here:
<head>
<title>left.php</title>
</head>
<body bgcolor="#224488" link=#00ffff vlink=#00ffff>
<?php
function readform()
{
global $username;
global $password;
$auth =true; // Assume user is not authenticated
if(($username)&&($password))
{
if (isset( $username ) && isset($password)) {
// Read the entire file into the variable $file_contents
$filename = "data.txt";
$fp = fopen( "data.txt", '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 );
$memb=count($lines);
// 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 ) {
if ($line) {
list( $user, $pass ) = explode( '->', $line );
}
if (($user == $username)&&($pass == $password)) {
// A match is found, meaning the user is authenticated.
// Stop the search.
$auth =false;
break;
}
}
}
}
if ($auth) {
echo"<font color=yellow ><b>Invalid Login</b></font>";
form();
} else {
echo"<font size=3 color=#00ffff><b>Hallo</b>,<i>$username</i></font>";
function form()
{
global $auth;
print("<form method=\"post\" action=\"left.php\">");
print("<table bgcolor=#white width=150>");
print("<tr bgcolor=#f1fbd5><td>");
print("<font size=2 >Username:</font><input name=\"username\" type=\"text\" maxlength=\"15\" size=\"8\">");
print("<br>");
print("<font size=2 >Password:</font><input name=\"password\" type=\"password\" maxlength=\"8\" size=\"8\">");
print("</td></tr>");
print("<tr ><td>");
print("<input name=\"beenhere\" type=\"hidden\" value=\"ture\">");
print("<center><input name=\"submit\" type=\"submit\" value=\"Login\" style=\"background-color:#fe9500\"></center>" );
print("</td></tr>");
print("</table>");
print("</form>");
}
if ($beenhere) {
readform();
} else {
form();
}
?>
</body>
IN MY DATA.TXT FILE
ken:ldj
jeff:45dsdg
The problem in here is when enter the correct username and password, i can't get in. so i change this line in readform:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if (($user == $username)&&($pass == $password))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TO
if ($user == $username)
then it works, and i do the samething for the password, then it doesn't work.
that means i can validate the username, but the password can't.