Guest User

Untitled

a guest
Aug 9th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.97 KB | None | 0 0
  1. <?php
  2. include_once("global.php");
  3. $message = '';
  4.  
  5. if($_SERVER['REQUEST_METHOD'] == "POST") {
  6.     $username = $_POST['username'];
  7.     $firstname = $_POST['firstname'];
  8.     $secondname = $_POST['lastname'];
  9.     $email = $_POST['email'];
  10.     $password = $_POST['password'];
  11.     $password2 = $_POST['password2'];
  12.  
  13.     if ((!$username) || (!$firstname) || (!$lastname) || (!$email) || (!$password) || (!$password2)){
  14.         $message = 'Please fill in all fields in the form below';
  15.  
  16.     }else{
  17.         if($password != $password2) {
  18.             $message = 'Your passwords do not match.';
  19.         }else {
  20.             $username = preg_replace("#[^0-9a-z]#i", "", $username);
  21.             $firstname = preg_replace("#[^0-9a-z]#i", "", $firstname);
  22.             $lastname = preg_replace("#[^0-9a-z]#i", "", $lastname);
  23.             $password = sha1($password);
  24.             $email = mysql_real_escape_string($email);
  25.  
  26.             $user_query = mysql_query("SELECT username FROM members WHERE username='$username' LIMIT 1") or die ("Could not check username");
  27.             $count_username = mysql_num_rows($user_query);
  28.  
  29.             $email_query = mysql_query("SELECT email FROM members WHERE email='$email' LIMIT 1") or die ("Could not check email");
  30.             $count_email = mysql_num_rows($email_query);
  31.  
  32.             if($count_username > 0){
  33.                 $message = 'Your username is already in use';
  34.             }else if($count_email > 0) {
  35.                 $message = 'Your email is already in use.';
  36.  
  37.             }else {
  38.                 $ip_address = $_SERVER['REMOTE_ADDR'];
  39.                 $query = mysql_query("INSERT INTO members (username, firstname, lastname, email, password, ip_address, sign_up_date) VALUES ('$username, $firstname, $lastname, $email, $password, ip_address, sign_up_date now())')") or die ("Could not insert data");
  40.                     $member_id = mysql_insert_id();
  41.                     mkdir("users/$member_id", 0755);
  42.                     $message = 'You succesfully registered.';
  43.             }
  44.         }
  45.  
  46.     }
  47.  
  48.  
  49.     }
  50.  
  51.  
  52. ?>
  53.  
  54.  
  55. <html DOCTYPE>
  56. <html>
  57.  
  58. <head>
  59.     <title>Welcome to our website!</title>
  60.  
  61.     <!-- CSS Imports -->
  62.     <link rel="stylesheet" href="css/style.css" />
  63.  
  64. </head>
  65. <body>
  66. <!-- Content -->
  67. <div class="container center">
  68.     <h1>Register to my website</h1>
  69.     <p><?=$message;?><p>
  70.     <form action="register.php" method="post"
  71.       <input type="text" name="username" placeholder="Username" /></br>
  72.       <input type="text" name="firstname" placeholder="First Name" /></br>
  73.       <input type="text" name="lastname" placeholder="Last Name" /></br>
  74.       <input type="text" name="email" placeholder="Email" /></br>
  75.       <input type="password" name="password" placeholder="Password" /></br>
  76.       <input type="password" name="password2" placeholder="Validate Password" /></br>
  77.       <input type="submit" value="Register" />
  78.     </form>
  79.  
  80. </div>
  81.  
  82.  
  83.  
  84.  
  85.  
  86. <!-- JS Imports -->
  87.  
  88. </body>
  89. </html>
Add Comment
Please, Sign In to add comment