Advertisement
Guest User

Untitled

a guest
Oct 30th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. <?php
  2.  
  3. ob_start();
  4.  
  5. include 'inc/database.php';
  6. include "captcha/simple-php-captcha.php";
  7.  
  8. if (!isset($_SESSION)) {
  9.     session_start();
  10. }
  11. if (!isset($_SESSION['captcha'])) {
  12.     $_SESSION['captcha'] = simple_php_captcha();
  13. }
  14.  
  15. if (isset($_SESSION['username'])) {
  16.     header('Location: index.php');
  17.     exit();
  18. }
  19.  
  20.  
  21. if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['confirmpassword']) && isset($_POST['email']) && isset($_POST['CaptchaClick'])) {
  22.  
  23.     $username = mysqli_real_escape_string($con, $_POST['username']);
  24.     $password = mysqli_real_escape_string($con, md5($_POST['password']));
  25.     $confirmpassword = mysqli_real_escape_string($con, md5($_POST['confirmpassword']));
  26.     $email = mysqli_real_escape_string($con, $_POST['email']);
  27.     $enteredCaptcha = $_POST['CaptchaClick'];
  28.    
  29.     if($enteredCaptcha != $_SESSION['captcha']['code']){
  30.     session_destroy();
  31.     die("Captcha is wrong.");
  32.    
  33.     header("Location: register.php?error=captcha");
  34.     }
  35.    
  36.     if($password != $confirmpassword){
  37.         session_destroy();
  38.         die("The confirmation password was not equal to the password.");
  39.        
  40.         header("Location: register.php?error=captcha");      
  41.     }
  42.    
  43.     if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  44.         session_destroy();    
  45.         die("The email entered was not correct.");
  46.        
  47.         header("Location: register.php?error=captcha");        
  48.     }
  49.    
  50.     $result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username'") or die(mysqli_error($con));
  51.     if(mysqli_num_rows($result) > 0){
  52.         die("This username already exists.");
  53.     }
  54.    
  55.     $result = mysqli_query($con, "SELECT * FROM `users` WHERE `email` = '$email'") or die(mysqli_error($con));
  56.     if(mysqli_num_rows($result) > 0){
  57.         die("This email already exists.");
  58.     }
  59.    
  60.     $ip = mysqli_real_escape_string($con, $_SERVER['HTTP_CF_CONNECTING_IP']);
  61.     $date = date('Y-m-d');
  62.    
  63.     mysqli_query($con, "INSERT INTO `users` (`username`, `password`, `email`, `date`, `ip`) VALUES ('$username', '$password', '$email', '$date', '$ip')") or die(mysqli_error($con));
  64.    
  65.     header("Location: login.php?action=registered");
  66.    
  67. }
  68.  
  69.  
  70. ?>
  71.  
  72. <!DOCTYPE html>
  73. <html lang="en">
  74. <head>
  75.         <meta charset="utf-8" />
  76.         <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  77.         <link rel="stylesheet" href="/assets/css/bg.css" />
  78.         <noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
  79.         <title>Oculous - Registration</title>
  80.         <link href="css/bootstrap-reset.css" rel="stylesheet">
  81.         <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
  82.         <body style="height:100%; width:100%;" class="login-body">
  83.         <center>
  84.         <form style="height:50%; width:50%;" class="form-signin" action="register.php" method="POST">
  85.         <br>
  86.         <br>
  87.         <h1 class="form-signin-heading">Register</h1>
  88.         <div class="login-wrap">
  89.         <br>
  90.             <input type="text" id="username" name="username" class="form-control" placeholder="Username" autofocus>
  91.              <br>
  92.             <input type="password" id="password" name="password" class="form-control" placeholder="Password">
  93.              <br>
  94.             <input type="password" id="confirmpassword" name="confirmpassword" class="form-control" placeholder="Confirm Password">
  95.              <br>
  96.             <input type="text" id="email" name="email" class="form-control" placeholder="Email">
  97.              <br>
  98.                 <?php
  99.                 echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA code">';
  100.                 ?>
  101.              <br>
  102.              <input name="CaptchaClick" id="CaptchaClick" cols="5" type="text" placeholder="Enter Captcha...">
  103.              <br>
  104.              <p style="height:100%; width:100%;"> By clicking the Sign up button you are agreeing to the <a href="ToS.php"> <font color="grey"> Terms of service </font> </p> </a>
  105.              <button style="height:90%; width:90%;" class="btn btn-lg btn-login btn-block" type="submit">Sign up</button>
  106.       </form>
  107.     <br> <br>
  108.     <div class="registration"> <font color="grey">
  109.     Already have an account?&nbsp </font>
  110.     <a class="" href="login.php">
  111.     Sign In
  112.     </a>
  113.     </div>
  114.     <script src="js/jquery.js"></script>
  115.     <script src="js/bootstrap.min.js"></script>
  116.     <footer id="footer">
  117.     <p class="copyright">&copy; Oculous Development</a>.</p>
  118.     </footer>
  119.     </center>
  120.   </body>
  121. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement