<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>News</title>
</head>
<body>
<?php
if(isset($_POST['username']) && isset($_POST['password'])) {
$passwd = file("etc/passwd");
for($i = 0; $i < count($passwd); $i++) {
$line = explode(":", $passwd[i]);
if($line[0] == $_POST['username']) {
// User found !
if(md5($_POST['password']) == $line[1]) {
// Password correct, logged in!
// Show what has to be showed.
echo("Logged in!");
break;
} else {
echo("Password errata.\n");
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
break;
}
}
if(feof($passwd)) {
// User not found !
echo("Nome utente errato o utente inesistente.\n");
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
}
}
} else {
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
}
?>
</body>
</html>
il formato di etc/passwd è:
utente:md5-della-password:Nome Cognome:email
il problema è: se pigio su OK! ritorna sempre e cmq alla pagina coi form senza fare quello dopo il primo if(), non da ne errori e ne niente...
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>News</title>
</head>
<body>
<?php
if(isset($_POST['username']) && isset($_POST['password'])) {
$passwd = file("etc/passwd");
for($i = 0; $i < count($passwd); $i++) {
$line = explode(":", $passwd[i]);
if($line[0] == $_POST['username']) {
// User found !
if(md5($_POST['password']) == $line[1]) {
// Password correct, logged in!
// Show what has to be showed.
echo("Logged in!");
break;
} else {
echo("Password errata.\n");
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
break;
}
}
if(feof($passwd)) {
// User not found !
echo("Nome utente errato o utente inesistente.\n");
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
}
}
} else {
echo(" <form action=\"index.php\" method=\"post\" enctype=\"text/plain\">
Username: <input size=\"20\" maxlength=\"20\" type=\"text\" name=\"username\" /><br />
Password: <input size=\"20\" maxlength=\"20\" type=\"password\" name=\"password\" /><br />
<input type=\"submit\" name=\"submit\" value=\"OK!\" />
</form>");
}
?>
</body>
</html>
il formato di etc/passwd è:
utente:md5-della-password:Nome Cognome:email
il problema è: se pigio su OK! ritorna sempre e cmq alla pagina coi form senza fare quello dopo il primo if(), non da ne errori e ne niente...

