Il mio problema è molto semplice io ho fatto un sistema di registrazione e accesso utenti che funziona benissimo solo che registra ben 2 volte l'utente. HELP !!!!!!!!!!!!!!!
Codice PHP:
<?php
require_once 'MySQL_Class.php';
require_once 'Controlli_Class.php';
require_once 'Cookies_Class.php';
Class Classe_Utenti
{
public $MySQL;
public $Controllo;
public $Cookie;
//Proprietà utilizzate per la registrazione
protected $Nome_REG;
protected $Cognome_REG;
protected $Email_REG;
protected $Password_REG;
protected $Conferma_Password_REG;
protected $Crypt_Password_REG;
//Proprietà utilizzate per il login
protected $ID_LOG;
protected $Email_LOG;
protected $Nome_LOG;
protected $Cognome_LOG;
protected $Password_LOG;
protected $Crypt_Password_LOG;
//Proprietà per la gestione degli errori ANCORA da gestire
public $messages = array( 1 => 'I campi Nome, Cognome, Email e Password sono obbligatori.
',
2 => 'Le due password non coincidono
.',
3 => 'Il nome e il cognome possono contenere solo caratteri dell\'alfabeto
.',
4 => 'La password deve contenere da x a y caratteri.
',
5 => 'Email esiste gia.
',
6 => 'Registrazione avvenuta con successo.
',
7 => 'I campi Email e Password non possono essere vuoti.
',
8 => 'Errore in fase di registrazione al database.
',
);
public $message_script;
//Metodo costruttore
public function __construct()
{
//Creo i tre oggetti che gestiscono i database, i controlli, e i cookie
$this->MySQL = new Classe_MySQL;
$this->Controllo = new Classe_Controlli;
$this->Cookie = new Classe_Cookie;
}
//Metodo per effettuare la registrazione dell'utente
public function Registrazione()
{
// se il form e i suoi input sono stati inviati
if (
isset($_POST['Registra']) AND
isset($_POST['Nome']) AND
isset($_POST['Cognome']) AND
isset($_POST['Email']) AND
isset($_POST['Password']) AND
isset($_POST['Conferma_Password'])
)
{
//Assegno i valori provenientio dalla form alle variabili
$this -> Nome_REG = $this->Controllo->Trimmera($_POST['Nome']);
$this -> Cognome_REG = $this->Controllo->Trimmera($_POST['Cognome']);
$this -> Email_REG = $this->Controllo->Trimmera($_POST['Email']);
$this -> Password_REG = $this->Controllo->Trimmera($_POST['Password']);
$this -> Conferma_Password_REG = $this->Controllo->Trimmera($_POST['Conferma_Password']);
$this -> Crypt_Password_REG = $this -> Cripta($this->Password_REG);
if ($this -> Controlla_REG_Input())
{
if(!$this -> Registra_Utente())
{
$this -> message_script = 8;
return FALSE;
}
else
{
$this -> message_script = 6;
return TRUE;
}
}
else return FALSE;
}
return FALSE;
}
// verifica che gli input siano corretti
protected function Controlla_REG_Input()
{
//Controllo che i campi non siano vuoti
if ($this->Controllo -> Vuota($this->Nome_REG) or $this->Controllo -> Vuota($this->Cognome_REG) or $this->Controllo -> Vuota($this->Email_REG) or $this->Controllo -> Vuota($this->Password_REG))
{
$this -> message_script = 1;
return FALSE;
}
//Controllo che le 2 password coincidano
else if ($this -> Password_REG != $this -> Conferma_Password_REG)
{
$this -> message_script = 2;
return FALSE;
}
//Controllo che nome e cognome rispettino le sintassi
else if (!$this->Controllo -> Verifica_Nome_o_Cognome($this->Nome_REG) or !$this->Controllo -> Verifica_Nome_o_Cognome($this->Cognome_REG))
{
$this -> message_script = 3;
return FALSE;
}
//Controllo che la password abbia un numero corretto di caratteri
else if (!$this->Controllo -> Verifica_Password($this -> Password_REG))
{
$this -> message_script = 4;
return FALSE;
}
//Controllo che l'email non sia gia presente
else if (!$this->Controllo -> Verifica_Esistenza_Email($this->Email_REG))
{
$this -> message_script = 5;
return FALSE;
}
else
return TRUE;
}
// esecuzione della query insert di registrazione
protected function Registra_Utente()
{
$this -> Nome_REG = $this->MySQL->Escape_MySQL($this -> Nome_REG);
$this -> Cognome_REG = $this->MySQL->Escape_MySQL($this -> Cognome_REG);
$this -> Email_REG = $this->MySQL->Escape_MySQL($this -> Email_REG);
$Query = " INSERT INTO Utenti
SET Nome='" . $this -> Nome_REG . "',
Cognome='" . $this -> Cognome_REG . "',
Email='" . $this -> Email_REG . "',
Password='" . $this -> Crypt_Password_REG ."'";
$this->MySQL->Connetti_DataBase();
if($Risultato = $this->MySQL->Query($Query))
{
$ID_Inserito = mysql_insert_id();
$this->MySQL->Disconnetti_DataBase();
return $ID_Inserito;
}
else
{
$this->MySQL->Disconnetti_DataBase();
return FALSE;
}
}
public function Accesso()
{
// se il form di login e i sui tutti input sono stati inviati
if (
isset($_POST['Accedi']) AND
isset($_POST['Email']) AND
isset($_POST['Password'])
)
{
$this -> Email_LOG = $this->Controllo->Trimmera($_POST['Email']);
$this -> Password_LOG = $this->Controllo->Trimmera($_POST['Password']);
$this -> Crypt_Password_LOG = $this -> Cripta($this -> Password_LOG);
if ($this -> Controlla_LOG_Input()) {
if ($this -> Richiedi_dati_LOG())
{
$this -> Cookie -> Crea_Cookie($this->ID_LOG);
return TRUE;
//$this -> message_script = 13;
}
else
{
//$this -> message_script = 12;
}
}
}
return FALSE;
}
// verifica che gli input del login non siano vuoti
protected function Controlla_LOG_Input() {
if($this->Controllo -> Vuota($this->Email_REG) or $this->Controllo -> Vuota($this->Password_REG))
{
$this -> message_script = 7;
return FALSE;
}
else return TRUE;
}
public function Verifica_Esistenza_Email($Email)
{
}
// esecuzione della qeury per verificare il login
protected function Richiedi_Dati_LOG()
{
$this -> Email_LOG = $MySQL->Escape_MySQL($this -> Email_LOG);
$Query = " SELECT * FROM utenti
WHERE Email='" . $this -> Email_LOG . "' AND password='" . $this -> Crypt_Password_LOG . "'";
$Risultato = $MySQL->Query($Query) or die(mysql_error());
$Num_Righe = $MySQL->Conta_Risultato($Risultato);
if ($Num_Righe == 1)
{
$Riga = mysql_fetch_assoc($Risultato);
$this -> ID_LOG = $Riga['ID_Utente'];
$this -> Nome_LOG = $Riga['Nome'];
$this -> Cognome_LOG = $Riga['Cognome'];
$this -> Email_LOG = $Riga['Email'];
return TRUE;
}
return FALSE;
}
//Metodo per criptare la password in SHA1
public function Cripta($Stringa)
{
return sha1($Stringa);
}
//Metodo per ottenere il messaggio settato nella classe
public function Ottienni_Messaggio()
{
if(isset($_GET['message']))
{
$this -> message_script = $_GET['message'];
}
$key = intval($this -> message_script);
if (array_key_exists($key, $this -> messages))
{
return $this -> messages[$key];
}
return FALSE;
}
}
//Codice che contiene la classe dell'oggetto azione
//require_once 'Utenti_Class.php';
//Creo la variabile che gestisce le azioni di registrazione e accesso e restituisce even
$Azione = new Classe_Utenti;
//Controllo se è stata richiesta un azione->registrazione se vero stampo a video la stringa Registrazione
if($Azione->Registrazione()) echo $Azione->Ottienni_Messaggio();
//Altrimenti Cntrollo se è stata richiesta un azione->accesso se vero stampo a video la stringa Accesso
else if($Azione->Accesso()) echo $Azione->Ottienni_Messaggio();
//Altrimenti controllo se ci sono messaggi di errore se vero stampo a video il primo messaggio di errore
else if($Azione->Ottienni_Messaggio()) echo $Azione->Ottienni_Messaggio();
//Altrimenti restituisci che non è stata eseguita nessun azione
else echo"Non è ancora stata eseguita nessun azione.";
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Prova</title>
</head>
<body>
<div style="position: absolute; top:10%; left:10%;background-color: red;">
<form action="Index.php" method="post">
<input type="text" name="Email" />
<input type="text" name="Nome" />
<input type="text" name="Cognome" />
<input type="password" name="Password" />
<input type="password" name="Conferma_Password">
<input type="submit" name="Registra">
</form>
</div>
<div style="position: absolute; top:10%; left:60%;background-color: blue;">
<form action="Index.php" method="post">
<input type="text" name="Email" />
<input type="password" name="Password" />
<input type="submit" name="Accedi">
</form>
</div>
</body>
</html>