Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. include '_variables.php';
  6. include 'helpers.php';
  7.  
  8. $uname=$_POST['uname'];
  9. $pword=$_POST['pword'];
  10. $error_messages = [];
  11.  
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. if(!isset($uname) || trim($uname) == '')
  14. {
  15. array_push($error_messages, 'Please Enter A Username');
  16. }
  17. if(!isset($pword) || trim($pword) == '')
  18. {
  19. array_push($error_messages, 'Please Enter A Password');
  20. }
  21. //if there are error messages
  22. if(count($error_messages) > 0){
  23.  
  24. //store the error messages in the session
  25. $_SESSION['regErrors'] = $error_messages;
  26. //redirect back to the login form
  27. header('Location: login.php?errors=' . count($error_messages));
  28. exit();
  29.  
  30. }
  31.  
  32. //if it reaches this point, that means there are no error messages
  33. //clear the session of any errors
  34. unset($_SESSION['regErrors']);
  35. $result = mysqli_query($conn,"SELECT * FROM Users WHERE username = '$uname' LIMIT 1");
  36.  
  37. if ($result->num_rows > 0) {
  38.  
  39. $user = mysqli_fetch_assoc($result);
  40. $hashed_password = $user['password'];
  41.  
  42. if (validate_pw($pword, $hashed_password)) {
  43.  
  44. $_SESSION['user'] = $user['username'];
  45. header('Location: profile.php');
  46. exit();
  47.  
  48. }else{
  49. // I want to turn this into array_push($error_messages)
  50. // and i know it needs to be before the code where it checks for any
  51. // errors but if i move this if statement above, what would take its place down here?
  52. echo "Invalid Password";
  53. }
  54. }else{
  55. // I want to turn this into array_push($error_messages)
  56. echo "Invalid Username";
  57. }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement