Phpauth\Auth::checkSession PHP Method

checkSession() public method

Function to check if a session is valid
public checkSession ( string $hash ) : boolean
$hash string
return boolean
    public function checkSession($hash)
    {
        $ip = $this->getIp();
        $block_status = $this->isBlocked();
        if ($block_status == "block") {
            $return['message'] = $this->lang["user_blocked"];
            return false;
        }
        if (strlen($hash) != 40) {
            return false;
        }
        $query = $this->dbh->prepare("SELECT id, uid, expiredate, ip, agent, cookie_crc FROM {$this->config->table_sessions} WHERE hash = ?");
        $query->execute(array($hash));
        if (!($row = $query->fetch(\PDO::FETCH_ASSOC))) {
            return false;
        }
        $sid = $row['id'];
        $uid = $row['uid'];
        $expiredate = strtotime($row['expiredate']);
        $currentdate = strtotime(date("Y-m-d H:i:s"));
        $db_ip = $row['ip'];
        $db_agent = $row['agent'];
        $db_cookie = $row['cookie_crc'];
        if ($currentdate > $expiredate) {
            $this->deleteExistingSessions($uid);
            return false;
        }
        if ($ip != $db_ip) {
            return false;
        }
        if ($db_cookie == sha1($hash . $this->config->site_key)) {
            return true;
        }
        return false;
    }