giovedì 7 maggio 2015

Correzione Verifica su classe Login Maggio 2015

Realizzare un’applicazione WEB che consenta la registrazione di più utenti. I dati saranno memorizzati all’interno di un array di nome Utenti. In seguito viene descritta l’organizzazione dell’applicazione:



PAGINA HTML DI INDEX PER LOGIN:
<html>
<head>
Pagina di Login
</head>
<body>

<form action="Controllo.php" method="post">
Username: <input type="text" name="user"><br>
Password: <input type="text" name="pass"><br>
<input type="submit" value="Entra">
</form>
Se non sei ancora registrato clicca <a href='nuovaRegistrazione.html'>"QUI"</a> e registrati

</body>
</html>

PAGINA HTML PER EFFETTUARE NUOVA REGISTRAZIONE:
<html>
<head>
Nuova Registrazione...
</head>
<body>
Inserisci i seguenti campi per procedere alla registrazione:<br><br>
<form action="Registra.php" method="POST">
Nome:     <input type="text" name="newNome"><br><br>
Cognome:  <input type="text" name="newCognome"><br><br>
eMail:    <input type="text" name="newEmail"><br><br>
Username: <input type="text" name="newUser"><br><br>
Password: <input type="text" name="newPass"><br><br>
<input type="submit" name="REGISTRATI!"><br><br>
</form>
</body>
</html>

CODICE PHP -> Controllo.php
<?PHP
class Login
{
var $Utenti = array();
var $username;
var $password;
var $fileDati;   //canale per salvataggio su FILE
public function __costruct()
{
$this->username=null;
$this->password=null;
}
public function Inserisci()
{
$this->username=$_POST["user"];
$this->password=$_POST["pass"];
}
public function Visualizza()   //metodo per visualizzare i dati ricevuti in input
{
foreach($this->Utenti as $buffer)
echo "ARRAY: $buffer<br>";
}
public function leggiDati()
{
$utenteRiconosciuto=0;
$this->fileDati=fopen("Database.txt", "r");
while(!feof($this->fileDati))
{
fscanf($this->fileDati,"%s",$this->Utenti[]);
}
$i=3;
$j=4;
while($i<count($this->Utenti))
{
if((strcmp($this->username, $this->Utenti[$i])==0)&&(strcmp($this->password, $this->Utenti[$i+1]==0))) 
$utenteRiconosciuto++;
$i=$i+5;
$j=$j+5;
}

if($utenteRiconosciuto>0)
echo "Utente riconosciuto!<br>";
else
echo "Utente non Riconosciuto...<br>";

fclose($this->fileDati);
}
}
$obj = new Login();
$obj->Inserisci();
$obj->leggiDati();
?>

CODICE PHP -> Registra.php

<?PHP
class Registrazione
{
var $Utenti = array();
var $username;
var $password;
var $nome;
var $cognome;
var $eMail;
var $reg;
var $fileDati;   //canale per salvataggio su FILE
public function __costruct()
{
$this->username=null;
$this->password=null;
$this->nome=null;
$this->cognome=null;
$this->eMail=null;
}
public function Inserisci()
{
$this->Utenti[]=$_POST["newNome"];
$this->Utenti[]=$_POST["newCognome"];
$this->Utenti[]=$_POST["newEmail"];
$this->Utenti[]=$_POST["newUser"];
$this->Utenti[]=$_POST["newPass"];
}
public function Visualizza()   //metodo per visualizzare i dati ricevuti in input
{
echo "username inserito: $this->username";
echo "<br>password inserita: $this->password";
}
public function scriviDati()
{
$this->fileDati=fopen("Database.txt", "a");
foreach($this->Utenti as $b)
fwrite($this->fileDati, $b."\r\n");   //scrivo su file il contenuto della variabile username e password
fclose($this->fileDati);
}
public function benvenuto()
{
$numeroUtentiRegistrati=count($this->Utenti);
$i=($numeroUtentiRegistrati-5);
$this->fileDati=fopen("Database.txt", "r");
echo "Benvenuto ".$this->Utenti[$i]. " ".$this->Utenti[$i+1];
}
}

$obj = new Registrazione();
$obj->Inserisci();
$obj->scriviDati();
$obj->benvenuto();
?>

Nessun commento:

Posta un commento