code_junkie

Is user logged in variable with PHP

Nov 14th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php if (Login::isAuthenticated()) { ?>
  2. <a href="/sign-out/">Sign Out</a>
  3. <?php } ?>
  4.  
  5. class Login
  6. {
  7. private static $_auth;
  8.  
  9. public function __construct($username, $rawPassword) {
  10.  
  11. global $db;
  12.  
  13. require('edit/users/config.php');
  14.  
  15. $hashedPassword = sha1(SALT . $_POST['password']);
  16.  
  17. $query = 'SELECT firstname FROM users WHERE user = "' . $db->cleanString($username) . '" AND pass = "' . $db->cleanString($hashedPassword) . '" LIMIT 1';
  18.  
  19.  
  20. $login = $db->query($query);
  21.  
  22. if ($login) {
  23.  
  24.  
  25. $_SESSION['username'] = $username;
  26. self::$_auth = true;
  27.  
  28.  
  29.  
  30. header('Location: ' . CONFIG_DIR_BASE);
  31.  
  32.  
  33. } else {
  34.  
  35. ErrorHandler::addErrorToStack('Your username and/or password did not match one on our system. ');
  36.  
  37. }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. public static function isAuthenticated() {
  44.  
  45.  
  46.  
  47. return self::$_auth;
  48.  
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. }
Add Comment
Please, Sign In to add comment