Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(!isset($_SESSION["userlogin"])){
  4. }
  5. else
  6. {
  7. $username = $_SESSION["userlogin"];
  8. }
  9. ?>
  10. <?php
  11. $reg = @$_POST['reg'];
  12. //declaring variables to prevent errors
  13. $first_name = ""; //First Name
  14. $last_name = ""; //Last Name
  15. $username = ""; //Username
  16. $email = ""; //Email
  17. $email2 = ""; //Email 2
  18. $password = ""; //Password
  19. $password2 = ""; // Password 2
  20. $signupdate = ""; // Sign up Date
  21. $usercheck = ""; // Check if username exists
  22. //registration form
  23. $first_name = strip_tags(@$_POST['first_name']);
  24. $last_name = strip_tags(@$_POST['last_name']);
  25. $username = strip_tags(@$_POST['username']);
  26. $email = strip_tags(@$_POST['email']);
  27. $email2 = strip_tags(@$_POST['email2']);
  28. $password = strip_tags(@$_POST['password']);
  29. $password2 = strip_tags(@$_POST['password2']);
  30. $signupdate = date("Y-m-d"); // Year - Month - Day
  31.  
  32. if ($reg) {
  33. if ($email==$email2) {
  34. // Check if user already exists
  35. $usercheck = mysql_query("SELECT username FROM users WHERE username='$username'");
  36. // Count the amount of rows where username = $un
  37. $check = mysql_num_rows($usercheck);
  38. //Check whether Email already exists in the database
  39. $echeck = mysql_query("SELECT email FROM users WHERE email='$email'");
  40. //Count the number of rows returned
  41. $emailcheck = mysql_num_rows($echeck);
  42. if ($check == 0) {
  43. if ($emailcheck == 0) {
  44. //check all of the fields have been filed in
  45. if ($username&&$first_name&&$last_name&&$email&&$email2&&$password&&$password2) {
  46. // check that passwords match
  47. if ($password==$password2) {
  48. // check the maximum length of username/first name/last name does not exceed 25 characters
  49. if (strlen($username)>25||strlen($first_name)>25||strlen($last_name)>25) {
  50. echo "The maximum limit for username/first name/last name is 25 characters!";
  51. }
  52. else
  53. {
  54. // check the maximum length of password does not exceed 25 characters and is not less than 5 characters
  55. if (strlen($password)>30||strlen($password)<5) {
  56. echo "Your password must be between 5 and 30 characters long!";
  57. }
  58. else
  59. {
  60. //encrypt password and password 2 using crypt before sending to database
  61. $password = crypt($password);
  62. $password2 = crypt($password2);
  63. $query = mysql_query("INSERT INTO users VALUES ('','$username','$first_name','$last_name','$email','$password','$signupdate','0')");
  64. header("Location: index.php");
  65. exit;
  66. }
  67. }
  68. }
  69. else {
  70. echo "Your passwords don't match!";
  71. }
  72. }
  73. else
  74. {
  75. echo "Please fill in all of the fields";
  76. }
  77. }
  78. else
  79. {
  80. echo "Sorry, but it looks like someone has already used that email!";
  81. }
  82. }
  83. else
  84. {
  85. echo "Username already taken ...";
  86. }
  87. }
  88. else {
  89. echo "Your E-mails don't match!";
  90. }
  91. }
  92. ?>
  93. <?php
  94. //Login Script
  95. if (isset($_POST["userlogin"]) && isset($_POST["passwordlogin"])) {
  96. $userlogin = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["userlogin"]); // filter everything but numbers and letters
  97. $passwordlogin = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["passwordlogin"]); // filter everything but numbers and letters
  98. $cryptpasswordlogin = crypt($passwordlogin);
  99. $sql = mysql_query("SELECT id FROM users WHERE username='$userlogin' AND password='$cryptpasswordlogin' LIMIT 1"); // query the person
  100. //Check for their existance
  101. $userCount = mysql_num_rows($sql);
  102. echo mysql_error();
  103. //Count the number of rows returned
  104. if ($userCount == 1) {
  105. while($row = mysql_fetch_array($sql)){
  106. $id = $row["id"];
  107. }
  108. $_SESSION["userlogin"] = $userlogin;
  109. header("home.php");
  110. exit();
  111. }else{
  112. echo 'That information is incorrect, try again';
  113. exit();
  114. }
  115. }
  116. ?>
  117. <div>
  118. <h2>Already a Memeber? Login below ...</h2>
  119. <form action="index.php" method="post" name="form1" id="form1">
  120. <input type="text" size="40" name="userlogin" id="user_login" class="auto-clear" placeholder="Username..." /><p />
  121. <input type="text" size="40" name="passwordlogin" id="password_login" placeholder="Password..." /><p />
  122. <input type="submit" name="button" id="button" value="Login to your account">
  123. </form>
  124. </div>
  125. <div>
  126. <h2>Sign up Below ...</h2>
  127. <form action="#.php" method="post">
  128. <input type="text" size="40" name="username" class="auto-clear" title="Username" placeholder="Username..."><p />
  129. <input type="text" size="40" name="first_name" class="auto-clear" title="First Name" placeholder="First name..."><p />
  130. <input type="text" size="40" name="last_name" class="auto-clear" title="Last Name" placeholder="Last name..."><p />
  131. <input type="text" size="40" name="email" class="auto-clear" title="Email" placeholder="Email..."><p />
  132. <input type="text" size="40" name="email2" class="auto-clear" title="Repeat Email" placeholder="Email again..."><p />
  133. <input type="password" size="40" name="password" placeholder="Password..."><p />
  134. <input type="password" size="40" name="password2" placeholder="Password again..."><p />
  135. <input type="submit" name="reg" value="Sign Up!">
  136. </form>
  137. </div>
  138. </div>
  139. </body>
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement