Advertisement
MBrendecke

UserLogin

Mar 30th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. class User
  4. {
  5.     private $values = [];
  6.  
  7.     public function __construct(string ...$keys)
  8.     {
  9.         foreach ($keys as $key) {
  10.             if (isset($_POST[$key])) {
  11.                 $values[$key] = $_POST[$key];
  12.             } else {
  13.                 $values['errors'] = array(
  14.                     "error_$key" => true
  15.                 );
  16.             }
  17.         }
  18.     }
  19.  
  20.     public function __get($name)
  21.     {
  22.         return $values[$name] ? : null;
  23.     }
  24. }
  25.  
  26. $user = new User(['email', 'first', 'last', 'uid', 'pwd1', 'pwd2']);
  27.  
  28. if (!isset($user->pwd1, $user->pwd2) || $user->pwd1 !== $user->pwd2) {
  29.     $user->errors = array(
  30.         "error_pwds" => true
  31.     );
  32. }
  33.  
  34. if ($user->errors !== []) {
  35.     header('Location: https://drohneglobal.de/login/registrierung.php?' . http_build_query($user->errors));
  36.     exit();
  37. }
  38.  
  39. try {
  40.     $passwort = password_hash($_POST['pwd1'], PASSWORD_DEFAULT);
  41.     $db = new PDO('mysql:host=.....;dbname=....', '....', '.....');
  42.  
  43.     $sql = 'INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES (?, ?, ?, ?, ?)';
  44.     $werte = [$user->first, $user->last, $user->email, $user->uid, $passwort];
  45.     $kommando = $db->prepare($sql);
  46.     $kommando->execute($werte);
  47.     header('Location: https://drohneglobal.de/login/registrierung.php');
  48. } catch (PDOException $e) {
  49.     echo 'Fehler: ' . htmlspecialchars($e->getMessage());
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement