Azzurra IRC Network Forum

Dove sbaglio?

xin · 10/05/2005 13:18 · #1
<!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... :cart10:
xin · 10/05/2005 13:20 · #2
uff pure vBulletin con le sue " " ... gh

qui il codice non parsato da vBulletin.. http://members.ferrara.linux.it/xin/test/gh.txt
}gu|do[z]{®© · 11/05/2005 12:17 · #3
andiamo per gradi.. dobbiamo prima di tutto capire se il form viene inviato o no... prova così:


<?php
error_reporting(E_ALL);
print_r($_POST);
if(isset($_POST['username']) && isset($_POST['password'])) {
echo 'inviato';
}
} 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>

vedi se hai errori e che valori ci stanno dentro £$_POST

ciauz
xin · 11/05/2005 15:39 · #4
il problema era enctype="text/plain" in <form .....>
se mi avanza tempo cerco anche il perchè... gh

cmq tnx :)
xin · 11/05/2005 16:00 · #5
be aware that when using an [x]html form, if you set the encoding type of the content to something else than 'application/x-www-form-urlencoded' (the default) or 'multipart/form-data', your script will fail on some (most?) browsers. i tried setting this to text/plain, and actually ns4.7 and ie5.x did not pass them to php for processing at all, and no form variables were defined.
using mozilla (m15), though, there were no problems using enctype='text/plain".