Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="errors-container">
- <?php
- if (isset($_POST['registerBtn']))
- {
- $username = $_POST['username'];
- $password = $_POST['passwd'];
- $repeat = $_POST['rpasswd'];
- $email = $_POST['email'];
- $terms = $_POST['terms'];
- $errors = array();
- if (empty($username) || empty($password) || empty($repeat) || empty($email))
- {
- $errors[] = 'Please fill in all required fields.';
- }
- $checkUsername = $odb -> prepare("SELECT * FROM `users` WHERE `username`= :username");
- $checkUsername -> execute(array(':username' => $username));
- $countUsername = $checkUsername -> rowCount();
- if ($countUsername != 0)
- {
- $errors[] = 'The username you have entered is already in use.';
- }
- $checkEmail = $odb -> prepare("SELECT * FROM `users` WHERE `email`= :email");
- $checkEmail -> execute(array(':email' => $email));
- $countEmail = $checkEmail -> rowCount();
- if ($countEmail0 != 0)
- {
- $errors[] = 'The email you have entered is already in use.';
- }
- if (strlen($_POST['passwd']) < 4) {
- $errors[] = 'The username you have entered is too short.';
- }
- if (strlen($_POST['username']) > 15) {
- $errors[] = 'The username you have entered is too long.';
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL))
- {
- $errors[] = 'You have entered an invalid e-mail address.';
- }
- if (!ctype_alnum($username))
- {
- $errors[] = 'The username you have entered is invalid.';
- }
- if ($password != $repeat)
- {
- $errors[] = 'The passwords you have entered does not match.';
- }
- if ($terms != 'agree')
- {
- $errors[] = 'You have to agree t.o.s before using our service.';
- }
- if (empty($errors))
- {
- $sha = hash("sha512", $password);
- $activation = generateRandomString();
- $insertUser = $odb -> prepare("INSERT INTO `users` VALUES(NULL, :username, :password, :email, 0, 0, 0, 0, 0)");
- $insertUser -> execute(array(':username' => $username, ':password' => $sha, ':email' => $email));
- //Send mail here
- echo '<div class="alert alert-success fade in"><button type="button" class="close close-sm" data-dismiss="alert"><i class="fa fa-times"></i></button><strong>Success!</strong> You have registered your account successfully! Redirecting..</div><meta http-equiv="refresh" content="3;url=login.php">';
- }
- else
- {
- echo '<div class="alert alert-block alert-danger fade in"><button type="button" class="close close-sm" data-dismiss="alert"><i class="fa fa-times"></i></button><strong>Oops!</strong><br />';
- foreach($errors as $error)
- {
- echo '- '.$error.'<br />';
- }
- echo '</div>';
- }
- }
- ?>
- </div>
- <form method="post" role="form" id="register">
- <div class="form-group">
- <label for="Username">Username</label>
- <input type="text" class="form-control" required name="username" id="username" placeholder="Username" autocomplete="off" autofocus/>
- </div>
- <div class="form-group">
- <label for="c-email">Email</label>
- <input type="email" class="form-control" required name="email" id="email" placeholder="E-Mail Address" autocomplete="off" />
- </div>
- <div class="form-group">
- <label for="pwd">Password:</label>
- <input type="password" class="form-control" required name="passwd" id="passwd" placeholder="Password" autocomplete="off" />
- </div>
- <div class="form-group">
- <label for="c-pwd">Confirm Password:</label>
- <input type="password" class="form-control" required id="rpasswd" name="rpasswd" placeholder="Confirm Password" autocomplete="off" />
- </div>
- <div class="checkbox">
- <label><input type="checkbox" name="terms" value="agree"> I agree to the <a>terms & conditions</a></label>
- </div>
- <input class="login-btn btn-block" type="submit" name="registerBtn" value="Sign Up"><i class="fa-plus"></i>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement