Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require ("connect.php");
- if(!empty($_POST))
- {
- if(empty($_POST['username'])) {
- die ("Please enter a username");
- }
- if(empty($_POST['password'])) {
- die ("Please enter a password");
- }
- if (empty($_POST['email'])) {
- die ("Please enter an email");
- }
- $query = "SELECT 1 FROM users WHERE username = :username";
- $query_params = array(
- ':username' => $_POST['username']
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Failed to run query: " . $ex->getMessage());
- }
- $row = $stmt->fetch();
- if($row)
- {
- die("This username is already in use");
- }
- $query = "
- INSERT INTO users (
- id,
- username,
- password,
- email,
- isAdmin
- ) VALUES (
- NULL,
- :username,
- :password,
- :email,
- 0
- )
- ";
- $options = [
- 'cost' => 12,
- 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
- ];
- $password = password_hash($_POST['password'], PASSWORD_BCRYPT, $options);
- $query_params = array(
- ':username' => $_POST['username'],
- ':password' => $password,
- ':email' => $_POST['email']
- );
- try
- {
- // Execute the query to create the user
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- // Note: On a production website, you should not output $ex->getMessage().
- // It may provide an attacker with helpful information about your code.
- die("Failed to run query: " . $ex->getMessage());
- }
- // This redirects the user back to the login page after they register
- header("Location: login.php");
- // Calling die or exit after performing a redirect using the header function
- // is critical. The rest of your PHP script will continue to execute and
- // will be sent to the user if you do not die or exit.
- die("Redirecting to login.php");
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Εστιατόριο</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <link rel="stylesheet" href="style.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="jumbotron text-center">
- <h1>Εστιατόριο</h1>
- <!--<img HEIGHT="140" WIDTH="140" src="img/black.png" alt="fork"> -->
- </br></br>
- </div>
- <div class="register">
- <h1>Register</h1>
- <form action="register.php" method="post">
- Username:<br />
- <input type="text" name="username" value="" />
- <br /><br />
- E-Mail:<br />
- <input type="text" name="email" value="" />
- <br /><br />
- Password:<br />
- <input type="password" name="password" value="" />
- <br /><br />
- <input type="submit" value="Register" />
- </form>
- </div>
- <footer>
- <div class="container-fluid text-center bg-gray2 copyr" >
- © Restaurant <?php echo date("Y") ?>
- </footer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement