Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class NewUser
- {
- public $conn;
- protected function DbConnect()
- {
- include "connessione_db.php";
- $this->conn = mysql_connect($host,$user,$password) OR die("Impossibile connettersi al database.");
- mysql_select_db($db, $this->conn);
- }
- protected function IsEmptyField()
- {
- if(empty($_POST['nome']) OR empty($_POST['email']) OR empty($_POST['password']))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- protected function VerifyPassword()
- {
- if($_POST['password'] == $_POST['password2'])
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- protected function EmailExists()
- {
- $this->DbConnect();
- $sql = "SELECT * FROM users WHERE email='$_POST[email]'";
- $res = mysql_query($sql, $this->conn);
- if($row = mysql_fetch_array($res))
- {
- mysql_close($this->conn);
- return TRUE;
- }
- else
- {
- mysql_close($this->conn);
- return FALSE;
- }
- }
- protected function VerifyEmail()
- {
- $pattern = "^([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(@)([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(\.[a-z]{2,4})$";
- if(ereg($pattern,$_POST['email']))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- public function ErrorResult($num)
- {
- header("Location: registrazione.php?alert=" . $num);
- die;
- }
- protected function ErrorReport()
- {
- if($this->IsEmptyField())
- {
- $this->ErrorResult(1);
- }
- if(!$this->VerifyPassword())
- {
- $this->ErrorResult(2);
- }
- if($this->EmailExists())
- {
- $this->ErrorResult(4);
- }
- if(!$this->VerifyEmail())
- {
- $this->ErrorResult(5);
- }
- $this->InsertNewUser();
- }
- protected function GetKey()
- {
- $car = "aAbBcCdDeEfFgGhHiIlLjJkKmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
- $dim = 40;
- srand((double)microtime()*1000000);
- $string = '' ;
- for($inc=0; $inc<$dim; $inc++)
- {
- $rand = rand(0, strlen($car)-1);
- $scar = substr($car, $rand, 1);
- $string = $string . $scar;
- }
- return $string;
- }
- protected function SendUserMail($key)
- {
- $content = "Benvenuto $_POST[nome],\r\n";
- $content .= "Per rendere attivo il tuo account,devi confermare la tua iscrizione cliccando sul link sotto.:\r\n\r\n";
- $content .= "http://www.fuckyoubitch.altervista.org/verifica_utente.php?key=" . $key;
- mail($_POST['email'], "Iscrizione al sito.", $content, "Da: io<[email protected]>");
- return;
- }
- protected function InsertNewUser()
- {
- $password = md5($_POST['password']);
- $key_control = $this->GetKey();
- $sql = "INSERT INTO utenti (nome,cognome,sesso,email,password,key_control) VALUES ('$_POST[nome]','$_POST[cognome]','$_POST[sesso]','$_POST[email]','$password','$key_control')";
- $this->DbConnect();
- mysql_query($sql,$this->conn);
- mysql_close($this->conn);
- $this->SendUserMail($key_control);
- }
- public function VerifyUser()
- {
- $sql = "SELECT id FROM users WHERE key_control='$_GET[key]'";
- $this->DbConnect();
- $res = mysql_query($sql,$this->conn);
- if($row = mysql_fetch_array($res))
- {
- $query = "UPDATE users SET ver=1,key_control='0' WHERE id='$row[id]'";
- mysql_query($query,$this->conn);
- mysql_close($this->conn);
- echo "Ottimo!Il tuo account è stato correttamente attivato.";
- }
- else
- {
- echo "Impossibile verificare l'account!";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment