Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. ## Displaying form is no form has already been submitted
  3. if(!isset($_POST['submit'])) {
  4.  
  5. ## Creating a 'goto' point for later use
  6. form: {
  7. ?>
  8. <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
  9. Username: <input type='text' name='username' /><br />
  10. Password: <input type='text' name='password' /><br />
  11. Password Confirmation: <input type='text' name='passwordc' /><br />
  12. Email: <input type='text' name='email' /><br />
  13. <input type='submit' name='submit' value='Sign Up' />
  14. </form>
  15. <?php
  16. }
  17. }
  18.  
  19. ## Processing if a form has been submitted
  20. else {
  21.  
  22. ## A little security measure
  23. $username = mysql_real_escape_string($_POST['username']);
  24. $username = htmlentities($username);
  25. $password = mysql_real_escape_string($_POST['password']);
  26. $passwordc = mysql_real_escape_string($_POST['passwordc']);
  27. $email = mysql_real_escape_string($_POST['email']);
  28.  
  29. ## Connecting to the database, you need to fill in with your information
  30. $con = mysql_connect('localhost', 'username', 'password');
  31. mysql_select_db('dbname', $con);
  32.  
  33. ## Checking to see if the username has been taken
  34. $check = sprintf("SELECT * FROM users WHERE Username='%s'", $username);
  35. $check_ = mysql_query($check);
  36. $check__count = mysql_num_rows($check_);
  37.  
  38. if($check__count > 0) { echo 'We already have a user signed up with that username. <br /><br />'; goto form; }
  39.  
  40. ## Checking to see if passwords match
  41. if($password != $passwordc) { echo 'Your two passwords do not match. <br /><br />'; goto form; }
  42.  
  43. ## Checking length of password
  44. if(strlen($password) < 4) { echo 'Your password is too short. Must be more than 4 characters. <br /><br />'; goto form; }
  45.  
  46. ## Checking to see if the email is taken
  47. $check = sprintf("SELECT * FROM users WHERE Email='%s'", $email);
  48. $check_ = mysql_query($check);
  49. $check__count = mysql_num_rows($check_);
  50.  
  51. if($check__count > 0) { echo 'We already have a user signed up with that email. <br /><br />'; goto form; }
  52.  
  53. ## Inserting information to the database, with the 'Type' set to 0, which means the account is not activated. You'll need to change it to 1 in order to activate the account
  54. $query = "INSERT INTO users (Username, Password, Email, Type) VALUES ('$username', '$password', '$email', '0')";
  55. mysql_query($query);
  56.  
  57. ## Sending a mail to you
  58. $to = 'youremail@yourdomain.com';
  59. $subject = 'User in need of activation';
  60. $message = 'A user has just registered with the username: ' . $username . '. He is need of activation.';
  61.  
  62. mail($to, $subject, $message);
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement