skeleton
02-04-2012, 14:59
Buon giorno,
vi posto immediatamente il codice che mi da problemi:
<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>
Il file UTENTI.txt
utente1
pass1
utente2
pass2
Ritengo il problema sia dato dall'if che controlla l'esattezza di $user e $password, visto che il messaggio che mi compare sempre è che non esiste alcun utente con il nome che inserisco.
Grazie in anticipo, buon pomeriggio.
vi posto immediatamente il codice che mi da problemi:
<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>
Il file UTENTI.txt
utente1
pass1
utente2
pass2
Ritengo il problema sia dato dall'if che controlla l'esattezza di $user e $password, visto che il messaggio che mi compare sempre è che non esiste alcun utente con il nome che inserisco.
Grazie in anticipo, buon pomeriggio.