|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 81
|
[PHP] Confrontare riga con $_POST
Buon giorno,
vi posto immediatamente il codice che mi da problemi: Codice:
<body>
<?php
$user = $_POST['user'];
$password = $_POST['password'];
$file = file("UTENTI.txt");
//Conto le righe del file
$rows = count(file("UTENTI.txt"));
for($i=0; $i<$rows; $i = $i+2){
//Se il nome utente è corretto e la password è corretta
if($file[$i] == $user and $file[$i+1] == $password){
setcookie('login', '$user', time() + 7200);
echo "<script language=\"JavaScript\">";
echo "alert('BENVENUTO $user!')";
echo "</script>";
$time = 0; //Tempo di attesa
$url = "index.php";
header("Refresh: $time; url=$url");
$access = 1;
$i = $rows;
}else{
$access = 0;
}
}
if($acces == 0){
echo "<script language=\"JavaScript\">";
echo "alert('NON ESISTE NESSUN UTENTE $user!')";
echo "</script>";
$time = 0; //Tempo di attesa
$url = "login.php";
header("Refresh: $time; url=$url");
}
?>
</body>
Codice:
utente1 pass1 utente2 pass2 Grazie in anticipo, buon pomeriggio. Ultima modifica di skeleton : 02-04-2012 alle 15:01. |
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 81
|
il problema è in $file..Mi prende solo l'elemento $file[ultimo_elemento], con tutti gli altri elementi dell'array genera un errore perchè sembra che proprio non esistano
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Aug 2011
Messaggi: 672
|
Prova così:
Codice:
$file = file("UTENTI.txt");
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
$u = explode(';', $line);
if($u[0] == 'nome' && $u[1] == 'pass')
{
bla bla bla
}
}
Codice:
utente1;pass1 utente2;pass2
__________________
Trattative positive: Ares17, TerrorSwing, HaraN.BanjO, Stevejedi, rtype, lucariello86, Leland Gaunt, antotuning, goudkamp Vendo Ricambi Acer Extensa 5235 -- Ricambi HP dv9000 -- Ricambi Hp dv6000 -- Ventole, Cavi, Adattatori, Schede di Rete, Ecc |
|
|
|
|
|
#4 | |
|
Member
Iscritto dal: Jul 2009
Messaggi: 81
|
Quote:
|
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Aug 2011
Messaggi: 672
|
Prova ad aggiungere delle stampe per vedere cosa non va,
ad esempio dentro il foreach stampa $line, $u[0], $u[1]
__________________
Trattative positive: Ares17, TerrorSwing, HaraN.BanjO, Stevejedi, rtype, lucariello86, Leland Gaunt, antotuning, goudkamp Vendo Ricambi Acer Extensa 5235 -- Ricambi HP dv9000 -- Ricambi Hp dv6000 -- Ventole, Cavi, Adattatori, Schede di Rete, Ecc |
|
|
|
|
|
#6 | |
|
Member
Iscritto dal: Jul 2009
Messaggi: 81
|
Quote:
Codice:
<html>
<head>
</head>
<body>
<?php
$user = $_POST['user'];
$password = $_POST['password'];
$file = file("UTENTI.txt");
//Conto le righe del file
$rows = count($file);
foreach ($lines as $line_num => $line) {
echo $line;
$u = explode(';', $line);
echo $u[0];
echo $u[1];
if($u[0] == $user && $u[1] == $password){
//Se il nome utente è corretto e la password è corretta
echo "<script language=\"JavaScript\">";
echo "alert('BENVENUTO $user!')";
echo "</script>";
$i = $rows;
$access = 1;
}else{
$access = 0;
}
}
if($acces == 0){
echo "<script language=\"JavaScript\">";
echo "alert('NON ESISTE NESSUN UTENTE $user!')";
echo "</script>";
}
?>
</body>
</html>
Ultima modifica di skeleton : 04-04-2012 alle 13:51. |
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Aug 2011
Messaggi: 672
|
probabilmente hai qualche errore di sintassi,
ma il tuo hosting non visualizza gli error di php. Che hosting usi? Non puoi provarlo in locale?
__________________
Trattative positive: Ares17, TerrorSwing, HaraN.BanjO, Stevejedi, rtype, lucariello86, Leland Gaunt, antotuning, goudkamp Vendo Ricambi Acer Extensa 5235 -- Ricambi HP dv9000 -- Ricambi Hp dv6000 -- Ventole, Cavi, Adattatori, Schede di Rete, Ecc |
|
|
|
|
|
#8 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 81
|
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Aug 2011
Messaggi: 672
|
scusa,
devi cambiare Codice:
$file = file("UTENTI.txt");
Codice:
$lines = file("UTENTI.txt");
__________________
Trattative positive: Ares17, TerrorSwing, HaraN.BanjO, Stevejedi, rtype, lucariello86, Leland Gaunt, antotuning, goudkamp Vendo Ricambi Acer Extensa 5235 -- Ricambi HP dv9000 -- Ricambi Hp dv6000 -- Ventole, Cavi, Adattatori, Schede di Rete, Ecc |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:28.




















