Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. include('Connection.php');
  4.  
  5. class Register
  6. {
  7.  
  8.     private $_error = [
  9.         "emptyerror" => "Bitte fülle alle Felder aus!",
  10.         "mailerror" => "Deine E-mail Adresse ist ungültig!",
  11.         "repwerror" => "Deine Passwörter stimmen nicht überein, bitte überprüfe deine Angaben!",
  12.         "existmailerror" => "Diese E-mail Adresse wird bereits benutzt!",
  13.         "existaccountnameerror" => "Dieser Benutzername ist bereits vergeben!",
  14.         "bothexisterror" => "E-mail und Benutzername ist bereits vergeben!"
  15.     ];
  16.  
  17.     public function __construct()
  18.     {
  19.         session_start();
  20.         if (isset($_SESSION['username'])) {
  21.             header("Location: ./index.php");
  22.             exit;
  23.         }
  24.     }
  25.  
  26.     public function register($username, $mail, $password, $repassword)
  27.     {
  28.         $connection = Connection::get();
  29.  
  30.         if (!empty($username) && !empty($mail) && !empty($password) && !empty($repassword)) {
  31.             if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
  32.                 $existcheck = $connection->query("SELECT * FROM users WHERE username = '" . $connection->real_escape_string($username) . "' OR mail = '" . $connection->real_escape_string($mail) . "'");
  33.                 if ($existcheck->num_rows > 0) {
  34.                     $existcheck = $existcheck->fetch_object();
  35.  
  36.  
  37.                     if ($existcheck->username == $username && $existcheck->mail == $mail) {
  38.                         echo $this->_error["bothexisterror"];
  39.                     } elseif ($existcheck->mail == $mail) {
  40.                         echo $this->_error["existmailerror"];
  41.                     } elseif ($existcheck->username == $username) {
  42.                         echo $this->_error["existaccountnameerror"];
  43.                     }
  44.                 } else {
  45.                     if ($password == $repassword) {
  46.                         $password = md5($password);
  47.                         $userimport = $connection->query("INSERT INTO users (username, password, mail) VALUES ('$username', '$password', '$mail')");
  48.                         $user_query = $connection->query("SELECT * FROM users WHERE id = '" . $connection->insert_id . "'");
  49.                         $user = $user_query->fetch_object();
  50.  
  51.                         $_SESSION['username'] = $user->username;
  52.                         $_SESSION['password'] = $user->password;
  53.                         $_SESSION['avatar'] = $user->avatar;
  54.                         $_SESSION['id'] = $user->id;
  55.                         header("Location: ./index.php");
  56.                         exit;
  57.  
  58.                     } else {
  59.                         echo $this->_error["repwerror"];
  60.                     }
  61.                 }
  62.             } else {
  63.                 echo $this->_error["mailerror"];
  64.             }
  65.         } else {
  66.             echo $this->_error["emptyerror"];
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement