Guest User

Untitled

a guest
Jan 5th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1.     public function __construct(DBConnection $dbConnection){
  2.         $this->m_dbConnection = $dbConnection;
  3.     }
  4.    
  5.     public function IsLoggedIn() {
  6.         //Är sessionen satt ska man visas som inloggad
  7.         if (isset($_SESSION[$this->sessionPosition])) {
  8.             return TRUE;
  9.         }
  10.         return FALSE;
  11.     }
  12.    
  13.     public function DoLogin($username, $password){
  14.         //Hämtar in användarnamnet och använder det i switchsatsen, sedan kontrollerar man om lösenordet stämmer.
  15.         //Stämmer båda variablerna startar sessionen och TRUE returneras.
  16.        
  17.         $this->m_dbConnection;
  18.        
  19.         $this->m_dbConnection->Connect();
  20.        
  21.         $sql = "SELECT userID FROM user WHERE username = ? AND password = ?";
  22.  
  23.         $stmt = $this->m_dbConnection->Prepare($sql);
  24.  
  25.         $stmt->bind_param("ss", $username, $password);
  26.        
  27.         $stmt->execute();
  28.        
  29.         if($stmt->fetch() === TRUE){
  30.             if (isset($_SESSION[$this->sessionPosition]) == FALSE) {
  31.                 $_SESSION[$this->sessionPosition] = 1;
  32.             }
  33.             else {
  34.                 $_SESSION[$this->sessionPosition] += 1;
  35.             }
  36.             return TRUE;
  37.         }
  38.         //return FALSE;
  39.        
  40.         $this->m_dbConnection->Close();
  41.     }
Add Comment
Please, Sign In to add comment