Guest User

Face9000

a guest
Feb 26th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class NewUser
  5. {
  6. public $conn;
  7. protected function DbConnect()
  8. {
  9. include "connessione_db.php";
  10.  
  11. $this->conn = mysql_connect($host,$user,$password) OR die("Impossibile connettersi al database.");
  12. mysql_select_db($db, $this->conn);
  13. }
  14.  
  15. protected function IsEmptyField()
  16. {
  17. if(empty($_POST['nome']) OR empty($_POST['email']) OR empty($_POST['password']))
  18. {
  19. return TRUE;
  20. }
  21. else
  22. {
  23. return FALSE;
  24. }
  25. }
  26.  
  27. protected function VerifyPassword()
  28. {
  29. if($_POST['password'] == $_POST['password2'])
  30. {
  31. return TRUE;
  32. }
  33. else
  34. {
  35. return FALSE;
  36. }
  37. }
  38.  
  39. protected function EmailExists()
  40. {
  41. $this->DbConnect();
  42. $sql = "SELECT * FROM users WHERE email='$_POST[email]'";
  43.  
  44. $res = mysql_query($sql, $this->conn);
  45. if($row = mysql_fetch_array($res))
  46. {
  47. mysql_close($this->conn);
  48. return TRUE;
  49. }
  50. else
  51. {
  52. mysql_close($this->conn);
  53. return FALSE;
  54. }
  55. }
  56.  
  57. protected function VerifyEmail()
  58. {
  59. $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})$";
  60.  
  61. if(ereg($pattern,$_POST['email']))
  62. {
  63. return TRUE;
  64. }
  65. else
  66. {
  67. return FALSE;
  68. }
  69. }
  70.  
  71. public function ErrorResult($num)
  72. {
  73. header("Location: registrazione.php?alert=" . $num);
  74. die;
  75. }
  76.  
  77. protected function ErrorReport()
  78. {
  79. if($this->IsEmptyField())
  80. {
  81. $this->ErrorResult(1);
  82. }
  83.  
  84. if(!$this->VerifyPassword())
  85. {
  86. $this->ErrorResult(2);
  87. }
  88.  
  89. if($this->EmailExists())
  90. {
  91. $this->ErrorResult(4);
  92. }
  93. if(!$this->VerifyEmail())
  94. {
  95. $this->ErrorResult(5);
  96. }
  97.  
  98. $this->InsertNewUser();
  99.  
  100. }
  101.  
  102. protected function GetKey()
  103. {
  104. $car = "aAbBcCdDeEfFgGhHiIlLjJkKmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
  105. $dim = 40;
  106. srand((double)microtime()*1000000);
  107. $string = '' ;
  108. for($inc=0; $inc<$dim; $inc++)
  109. {
  110. $rand = rand(0, strlen($car)-1);
  111. $scar = substr($car, $rand, 1);
  112. $string = $string . $scar;
  113. }
  114.  
  115. return $string;
  116. }
  117.  
  118. protected function SendUserMail($key)
  119. {
  120. $content = "Benvenuto $_POST[nome],\r\n";
  121. $content .= "Per rendere attivo il tuo account,devi confermare la tua iscrizione cliccando sul link sotto.:\r\n\r\n";
  122. $content .= "http://www.fuckyoubitch.altervista.org/verifica_utente.php?key=" . $key;
  123.  
  124. mail($_POST['email'], "Iscrizione al sito.", $content, "Da: io<[email protected]>");
  125.  
  126. return;
  127. }
  128.  
  129. protected function InsertNewUser()
  130. {
  131. $password = md5($_POST['password']);
  132. $key_control = $this->GetKey();
  133.  
  134. $sql = "INSERT INTO utenti (nome,cognome,sesso,email,password,key_control) VALUES ('$_POST[nome]','$_POST[cognome]','$_POST[sesso]','$_POST[email]','$password','$key_control')";
  135.  
  136. $this->DbConnect();
  137.  
  138. mysql_query($sql,$this->conn);
  139.  
  140. mysql_close($this->conn);
  141.  
  142. $this->SendUserMail($key_control);
  143. }
  144.  
  145. public function VerifyUser()
  146. {
  147. $sql = "SELECT id FROM users WHERE key_control='$_GET[key]'";
  148. $this->DbConnect();
  149. $res = mysql_query($sql,$this->conn);
  150.  
  151. if($row = mysql_fetch_array($res))
  152. {
  153. $query = "UPDATE users SET ver=1,key_control='0' WHERE id='$row[id]'";
  154. mysql_query($query,$this->conn);
  155. mysql_close($this->conn);
  156. echo "Ottimo!Il tuo account è stato correttamente attivato.";
  157. }
  158. else
  159. {
  160. echo "Impossibile verificare l'account!";
  161. }
  162. }
  163.  
  164. ?>
Advertisement
Add Comment
Please, Sign In to add comment