Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. <?php
  2. require ("connect.php");
  3.  
  4. if(!empty($_POST))
  5. {
  6.  
  7. if(empty($_POST['username'])) {
  8.  
  9. die ("Please enter a username");
  10. }
  11.  
  12. if(empty($_POST['password'])) {
  13.  
  14. die ("Please enter a password");
  15. }
  16.  
  17. if (empty($_POST['email'])) {
  18.  
  19. die ("Please enter an email");
  20. }
  21.  
  22. $query = "SELECT 1 FROM users WHERE username = :username";
  23.  
  24. $query_params = array(
  25. ':username' => $_POST['username']
  26. );
  27.  
  28. try
  29. {
  30. $stmt = $db->prepare($query);
  31. $result = $stmt->execute($query_params);
  32. }
  33. catch(PDOException $ex)
  34. {
  35. die("Failed to run query: " . $ex->getMessage());
  36. }
  37.  
  38. $row = $stmt->fetch();
  39.  
  40. if($row)
  41. {
  42. die("This username is already in use");
  43. }
  44.  
  45. $query = "
  46. INSERT INTO users (
  47. id,
  48. username,
  49. password,
  50. email
  51. ) VALUES (
  52. NULL,
  53. :username,
  54. :password,
  55. :email
  56. )
  57. ";
  58.  
  59. $options = [
  60. 'cost' => 12,
  61. 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
  62. ];
  63.  
  64. $password = password_hash($_POST['password'], PASSWORD_BCRYPT, $options);
  65.  
  66.  
  67. $query_params = array(
  68. ':username' => $_POST['username'],
  69. ':password' => $password
  70. );
  71.  
  72. try
  73. {
  74. // Execute the query to create the user
  75. $stmt = $db->prepare($query);
  76. $result = $stmt->execute($query_params);
  77. }
  78. catch(PDOException $ex)
  79. {
  80. // Note: On a production website, you should not output $ex->getMessage().
  81. // It may provide an attacker with helpful information about your code.
  82. die("Failed to run query: " . $ex->getMessage());
  83. }
  84.  
  85. // This redirects the user back to the login page after they register
  86. header("Location: login.php");
  87.  
  88. // Calling die or exit after performing a redirect using the header function
  89. // is critical. The rest of your PHP script will continue to execute and
  90. // will be sent to the user if you do not die or exit.
  91. die("Redirecting to login.php");
  92. }
  93.  
  94. ?>
  95.  
  96. <!DOCTYPE html>
  97. <html>
  98. <head>
  99. <title>Εστιατόριο</title>
  100. <meta charset="utf-8">
  101. <meta name="viewport" content="width=device-width, initial-scale=1">
  102. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  103. <link rel="stylesheet" href="style.css">
  104. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  105. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  106. </head>
  107. <body>
  108.  
  109. <div class="jumbotron text-center">
  110. <h1>Εστιατόριο</h1>
  111. <!--<img HEIGHT="140" WIDTH="140" src="img/black.png" alt="fork"> -->
  112. </br></br>
  113. </div>
  114.  
  115. <div class="register">
  116. <h1>Register</h1>
  117. <form action="register.php" method="post">
  118. Username:<br />
  119. <input type="text" name="username" value="" />
  120. <br /><br />
  121. E-Mail:<br />
  122. <input type="text" name="email" value="" />
  123. <br /><br />
  124. Password:<br />
  125. <input type="password" name="password" value="" />
  126. <br /><br />
  127. <input type="submit" value="Register" />
  128. </form>
  129. </div>
  130. <footer>
  131.  
  132. <div class="container-fluid text-center bg-gray2 copyr" >
  133.  
  134. &copy; Restaurant <?php echo date("Y") ?>
  135.  
  136. </footer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement