Ejemplo n.º 1
0
        require_once SYS_PATH . 'dbConfig.php';
        $dbc = new DBC(0);
        // 0 defines database id in dbConfig.php
        $db = $dbc->getConnection();
        $db->exec("SET CHARACTER SET utf8");
        try {
            $sql = "SELECT id FROM `users` WHERE `key`= ? AND `pass`= ?";
            $stmt = $db->prepare($sql);
            $stmt->execute(array($key, $value));
            $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $rows = $stmt->fetchAll();
            if (empty($rows)) {
                header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
                echo 'You are not authorised to access this page.';
                exit(1);
                // EXIT_ERROR
            }
            $dbc->closeConnection();
        } catch (PDOException $e) {
            header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
            echo 'You are not authorised to access this page.';
            exit(1);
            // EXIT_ERROR
        }
    } else {
        header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
        echo 'You are not authorised to access this page.';
        exit(1);
        // EXIT_ERROR
    }
}