Guest User

Untitled

a guest
Feb 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. Register.php
  2.  
  3. <?php
  4. session_start();
  5. include realpath("./inc/class.template.php");
  6.  
  7. $template->_get("header.html");
  8. $template->_set(array(
  9. 'TZ_TITLE' => 'Tezzy',
  10. 'BB_SUBT' => 'Index',
  11. 'BB_USER' => 'Username'
  12. ));
  13.  
  14. if(isset($_POST['submitR'])) {
  15.  
  16. $username = $_POST['username'];
  17. $password = $_POST['password'];
  18. $passwordC = $_POST['passwordC'];
  19. $email = $_POST['email'];
  20. $ipaddress = $_SERVER['REMOTE_ADDR'];
  21. $session = session_id();
  22.  
  23. if($username == '' or $password == '' or $passwordC == '' or $email == '') {
  24. header("Location: ./register.php?error=1"); // Tells to fill in all fields
  25. } elseif ($password != $passwordC) {
  26. header("Location: ./register.php?error=2"); // Checks to see if password is correct
  27. } elseif (mysql_num_rows(mysql_query("SELECT * from users WHERE username='" . $_POST['username'] . "'")) == 1) {
  28. header("Location: ./register.php?error=3"); // Checks to see if username is taken
  29. } elseif (mysql_num_rows(mysql_query("SELECT * from users WHERE email='" . $_POST['email'] . "'")) == 1) {
  30. header("Location: ./register.php?error=4"); // Checks to see if email is taken
  31. } else {
  32. function sha512($str) { return hash("sha512", $str); }
  33. $password = sha512($password);
  34. mysql_query("INSERT INTO users (username,password,email,ip,session) VALUES('{$username}','{$password}','{$email}',{$ipaddress}','{$session}')");
  35. header("Location: ./register.php?success=1");
  36. }
  37. }
  38.  
  39. $template->_get("register_body.html");
  40. $template->_set(array(
  41. 'TZ_TITLE' => 'Tezzy'
  42. ));
  43.  
  44. $template->_get("footer.html");
  45. $template->_set(array(
  46. 'BB_TITLE' => 'Tezzy'
  47. ));
  48. ?>
  49.  
  50. Register Template:
  51.  
  52. <form action="./register.php" method="POST">
  53. Username: <input type="text" name="username"><br />
  54. Password: <input type="password" name="password"><br />
  55. Password Confirm: <input type="password" name="password"><br />
  56. Email: <input type="password" name="password"><br />
  57. <input type="submit" name="submitR" value="Register">
  58. </div>
Add Comment
Please, Sign In to add comment