Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require("connect.php");
  4. if(isset($_SESSION["user"])){
  5. #Check to see if the user has requested to confirm there account from the code sent to there email
  6. if(isset($_POST["confirm"])){
  7. $confirmcode = $_POST["confirmcode"];
  8. #Retrieve users confirm code from database
  9. $sqlgetconfirm = "SELECT confirmcode FROM users WHERE username='".$_SESSION["user"]."'";
  10. $resgetconfirm = mysql_query($sqlgetconfirm);
  11. while($row = mysql_fetch_array($resgetconfirm)){
  12. $confirmcodegot = $row["confirmcode"];
  13.  
  14. }
  15. if($confirmcodegot == $confirmcode){
  16. $sqlconfirmed = "UPDATE users SET confirmed=1 WHERE username='".$_SESSION["user"]."'";
  17. mysql_query($sqlconfirmed);
  18. header("location: index.php?confirmed=true");
  19. }else{
  20. echo "<h1 style='color:red;'>Incorrect confirmation code!</h1>";
  21. }
  22. }
  23.  
  24.  
  25.  
  26. echo "Welcome ".$_SESSION["user"];
  27. echo "<form action='' method='post'><input type='submit' placeholder='logout' name='logout' value='Logout'></form>";
  28. $user = $_SESSION["user"];
  29. #Check to see if account has been confirmed
  30. $sqlconfirm = "SELECT confirmed, email FROM users WHERE username='".$user."'";
  31. $resconfirm = mysql_query($sqlconfirm);
  32. while($row = mysql_fetch_array($resconfirm)){
  33. $confirmed = $row["confirmed"];
  34. $email = $row["email"];
  35. }
  36. if($confirmed == 0){
  37. echo '<h1 style="color:red">Please confirm your account. An email has been sent to '.$email.'</h1>';
  38. echo '
  39. <form action="" method="post">
  40. <input type="text" name="confirmcode" palceholder="Confirm Code">
  41. <input type="submit" value="Confirm" name="confirm">
  42. </form>
  43.  
  44. ';
  45. }
  46. } else {
  47. echo '<html>
  48. <form action="" method="post">
  49. <h2>Login</h2>
  50. <input type="text" name="username" placeholder="Username">
  51. <input type="password" name="password" placeholder="Password">
  52. <input type="submit" name="submit">
  53. <h4><i>Dont have an account yet? <a href="register.php">Sign up</a>
  54. </form>
  55. </html>';
  56. }
  57.  
  58. #Check to see if the user has successfully confirmed there email
  59. if(isset($_GET["confirmed"])){
  60. echo '<h1 style="color:green">Successfully confirmed your email!</h1>';
  61. sleep(2);
  62. header("location: index.php");
  63. }
  64.  
  65. #Check to see if user has requested to logout
  66. if(isset($_POST["logout"])){
  67. session_destroy();
  68. header("location: index.php?loggedout=true");
  69. }
  70. if(isset($_GET["loggedout"])){
  71. echo '<h1 style="color:red">Successfully logged out!</h1>';
  72. }
  73.  
  74. #Login and create session
  75. if(isset($_POST["submit"])){
  76. $username = $_POST["username"];
  77. $password = $_POST["password"];
  78. $sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";
  79. $res = mysql_query($sql);
  80.  
  81. if(mysql_num_rows($res) < 1){
  82. echo '<h1 style="color:red">Account not found! Try again.</h1>';
  83. }else{
  84. echo "<h1 style='color:green;'>";
  85. echo "User account found...";
  86. echo "Creating session...";
  87. echo "</h1>";
  88. $_SESSION["user"] = $username;
  89. header("location: index.php");
  90.  
  91. }
  92.  
  93. }
  94.  
  95. ?>
  96.  
  97.  
  98. -- Register page
  99.  
  100. <?php
  101. require("connect.php");
  102. if(isset($_SESSION["user"])){
  103. echo "You are already logged in!";
  104. echo "Redirecting to home page...";
  105. sleep(3);
  106. header("location: index.php");
  107. }else{
  108.  
  109. echo '
  110. <html>
  111. <form action="" method="post">
  112. <input type="text" name="username" placeholder="Username">
  113. <input type="email" name="email" placeholder="Email">
  114. <input type="email" name="emailretype" placeholder="Retype Email">
  115. <input type="password" name="password" placeholder="Password">
  116. <input type="password" name="passwordretype" placeholder="Retype Password">
  117. <input type="submit" name="submit">
  118. </form>
  119. ';
  120.  
  121. if(isset($_POST["submit"])){
  122. $username = $_POST["username"];
  123. $email = $_POST["email"];
  124. $emailretype = $_POST["emailretype"];
  125. $password = $_POST["password"];
  126. $passwordretype = $_POST["passwordretype"];
  127.  
  128. #Check if the user forgot any values
  129. if(empty($username) or empty($email) or empty($emailretype) or empty($password) or empty($passwordretype)){echo "<h1 style='color:red;'>You've forgot to input somthing!</h1>";} else {
  130.  
  131. if($email == $emailretype){
  132. if($password == $passwordretype){
  133. #Generate a confirmation code
  134. $confirmationcode = rand(1,9).rand(1,9).rand(1,9).rand(1,9);
  135. echo $confirmationcode;
  136. #code to register
  137. $sql = "SELECT * FROM users WHERE username='".$username."' OR email='".$email."'";
  138. $res = mysql_query($sql);
  139. if(mysql_num_rows($res) > 0){
  140. echo "<h1 style='color:red;'>An account with this username or email already exists!</h1>";
  141. }else{
  142. $sql2 = "INSERT INTO users (username, email, password, confirmcode) VALUES ('".$username."', '".$email."', '".$password."', '".$confirmationcode."')";
  143. $res2 = mysql_query($sql2);
  144. if(!$res2){
  145. echo "<h1 style='color:red;'>An error occured! Please retry.</h1>";
  146. }else{
  147. echo "<h1 style='color:greed;'>Account created! Login <a href='index.php'>Here</a></h1>";
  148. #$to = $email;
  149. #$subject = "Please confirm your email!";
  150. #$txt = "Please confirm your email on the login page. This is your unique code: ". $confirmationcode;
  151. #$headers = "From: admin@willhelstrip.co.uk";
  152. #mail($to,$subject,$txt,$headers);
  153. }
  154. }
  155.  
  156. }else{
  157. echo "<h1 style='color:red;'>Your passwords did not match!</h1>";
  158. }
  159. }else{
  160. echo "<h1 style='color:red;'>Your emails did not match!</h1>";
  161. }
  162.  
  163. }
  164. }
  165. }
  166.  
  167. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement