Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2. //Initialiseer variabelen
  3. $email = "undefined";
  4. $name = "undefined";
  5. $pass = "undefined";
  6. $ip = "undefined";
  7.  
  8.  
  9. if(isPostValid()){
  10. //Check of email aanwezig is in de database
  11. if(!isEmailInUse() && !isUsernameInUse()){
  12. registerUser();
  13. }
  14. }else{
  15. echo "POST UNSUCCESFUL: POST DATA INCOMPLETE OR NOT FOUND";
  16. }
  17.  
  18.  
  19. function isPostValid(){
  20. if(isset($_POST['email']) && isset($_POST['password']) && isset($_POST['username'])){
  21. return true;
  22. }else{
  23. return false;
  24. }
  25. }
  26.  
  27. function isEmailInUse(){
  28. //Verbind met de database
  29. include("../sql/loginsql.php");
  30. //Vul variabelen
  31. $email = $_POST['email'];
  32. $pass = $_POST['password'];
  33. $name = $_POST['username'];
  34. $ip = $_SERVER['REMOTE_ADDR'];
  35. $query = $conn->prepare("SELECT * FROM users where email = :email");
  36. $query->bindParam(':email', $email, PDO::PARAM_STR, 256);
  37. $query->execute();
  38. if($query->rowCount() == 0){
  39. echo('email not in use');
  40. return false;
  41. }
  42. else{
  43. echo('email in use');
  44. return true;
  45. }
  46. }
  47. function isUsernameInUse(){
  48. //Verbind met de database
  49. include("../sql/loginsql.php");
  50. //Vul variabelen
  51. $username = $_POST['username'];
  52. $query = $conn->prepare("SELECT * FROM users where username = :username");
  53. $query->bindParam(':username', $username, PDO::PARAM_STR, 256);
  54. $query->execute();
  55. if($query->rowCount() == 0){
  56. echo('un not in use');
  57. return false;
  58. }
  59. else{
  60. echo('un in use');
  61. return true;
  62. }
  63. }
  64.  
  65. function registerUser(){
  66. $email = $_POST['email'];
  67. $pass = $_POST['password'];
  68. $name = $_POST['username'];
  69. $ip = $_SERVER['REMOTE_ADDR'];
  70. //Verbind met de database
  71. include("../sql/loginsql.php");
  72. $query = $conn->prepare("INSERT INTO users (username, email, password, reg_ip) VALUES (:name, :email, :pass, :ip)");
  73. $query->bindParam(':name', $name, PDO::PARAM_STR, 256);
  74. $query->bindParam(':email', $email, PDO::PARAM_STR, 256);
  75. $query->bindParam(':pass', $pass, PDO::PARAM_STR, 256);
  76. $query->bindParam(':ip', $ip, PDO::PARAM_STR, 256);
  77. $query->execute();
  78. header('Location: ../index/index.php');
  79.  
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement