Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function isLoggedIn() {
- if(count($this->userInfo)) {
- $id = !empty($this->userInfo['id']) ? intval($this->userInfo['id']) : false;
- $username = !empty($this->userInfo['username']) ? $this->userInfo['username'] : false;
- $password = !empty($this->userInfo['password']) ? $this->userInfo['password'] : false;
- if($id !== false && $username !== false && $password !== false) {
- try {
- $stmt = $this->prepare("SELECT id, username, password FROM users WHERE id = :id AND username = :username AND password = :password LIMIT 1");
- $stmt->bindParam(":id", $id, PDO::PARAM_INT);
- $stmt->bindParam(":username", $username, PDO::PARAM_STR);
- $stmt->bindParam(":password", $password, PDO::PARAM_STR);
- $stmt->execute();
- $stmt->bindColumn("id", $id, PDO::PARAM_INT);
- $stmt->bindColumn("username", $username, PDO::PARAM_STR);
- $stmt->bindColumn("password", $password, PDO::PARAM_STR);
- $result = $stmt->fetch(PDO::FETCH_BOUND);
- if($result) {
- return $this->userInfo === compact("id", "username", "password");
- }
- } catch(PDOException $e) {
- die("PDO Error: ({$e->getCode()}) {$e->getMessage()}");
- }
- }
- }
- return false;
- }
Add Comment
Please, Sign In to add comment