Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. {
  3.  
  4. include("config.php");
  5.  
  6. $error = "";
  7. $username = "";
  8. $msgGame = "";
  9.  
  10. if($_SERVER["REQUEST_METHOD"] == "POST" AND isset($_POST['back'])) {
  11. header("location: login.php");
  12. }
  13. else if($_SERVER["REQUEST_METHOD"] == "POST") {
  14.  
  15. // username and password sent from form
  16. $username = mysqli_real_escape_string($db,$_POST['username']);
  17. $pass1 = mysqli_real_escape_string($db,$_POST['password1']);
  18. $pass2 = mysqli_real_escape_string($db,$_POST['password2']);
  19.  
  20. //searches for username that is aptemting to register
  21. $sql = "SELECT id FROM users WHERE username = '$username'";
  22. $result = mysqli_query($db,$sql);
  23.  
  24. $count = mysqli_num_rows($result);
  25.  
  26. // If no username not found in database then proceed
  27. if($count == 0) {
  28.  
  29. // Checks if password matches and is at least 6 letters/symbols long
  30. if ($pass1 == $pass2 AND strlen($pass1) > 5){
  31. //encrypts password (twice)
  32. $pass = md5(md5($pass1));
  33. $sql = "INSERT INTO users (username, password) VALUES ('$username', '$pass')";
  34. $result = mysqli_query($db,$sql);
  35. // if registration successful then continue to next page
  36. if ($result){
  37. if (isset($_POST['game'])){
  38. $msgGame = "SUCCESS";
  39. }
  40. else{
  41. header("location: registration_success.php");
  42. }
  43. }else{
  44. $msgGame = "FAIL";
  45. $error = "Could not add user...";
  46. }
  47. }else{
  48. $msgGame = "FAIL";
  49. $error = "Password not matching or too short (min 6 symbols)!! Please try again.";
  50. }
  51. }else {
  52. $msgGame = "FAIL";
  53. $error = "Username <u>". $username."</u> already exists, sorry!";
  54. }
  55.  
  56. // checks is game variable is set
  57. if (isset($_POST['game'])){
  58. // displays msg and and returns
  59. echo $msgGame;
  60. return; // (return aka don't run rest of the code)
  61. }
  62. }
  63. } catch(exception $ex){ echo $ex; }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement