Advertisement
Guest User

loginSubmit function with permssion session

a guest
Apr 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public function loginSubmit($un, $pw){
  2.  
  3. // TODO pull correct login stuff
  4. $correctUsername = 'admin';
  5. $correctPassword = '123';
  6.  
  7. // bounce to login if unsuccessful
  8. if($un != $correctUsername)
  9. header('Location: '.BASE_URL.'/login');
  10. elseif($pw != $correctPassword)
  11. header('Location: '.BASE_URL.'/login');
  12.  
  13. // if correct username/pw, send to confirmation screen
  14. else {
  15. $_SESSION['username'] = $un;
  16.  
  17. // Adding correct permissions to session data
  18. // build query
  19. $q = sprintf("SELECT * FROM User_Data WHERE username = %d;",
  20. $un
  21. );
  22. $result = $db->query($q); // execute query
  23.  
  24. // make sure we found something
  25. if($result->num_rows == 0) {
  26. return null;
  27. } else {
  28. $row = $result->fetch_assoc(); // get results as associative array
  29.  
  30. $_SESSION['permissions'] = $row['permissions'];
  31.  
  32. }
  33.  
  34. // Moves to profile page
  35. header('Location: '.BASE_URL.'/'.$un);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement