Ejemplo n.º 1
0
     // EXIT_ERROR
 }
 //Depending on authentication method validate key-value pair
 if (AUTH_TYPE === 'plain') {
     $authorizer = array('user1' => '65h4g9874h65464h894hg65487h64', 'user2' => 'gfd46165fdh897yt6541616df7rer', 'user3' => 'gg8971646uo561dfh546d78te564r', 'user4' => 'uku55fh156456j3213gd1651af654');
     if (strcmp($authorizer[$key], $value) !== 0) {
         header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
         echo 'You are not authorised to access this page.';
         exit(1);
         // EXIT_ERROR
     }
 } elseif (AUTH_TYPE === 'db') {
     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) {
Ejemplo n.º 2
0
 function __construct()
 {
     $dbc = new DBC(0);
     $this->db = $dbc->getConnection();
     $this->db->exec("SET CHARACTER SET utf8");
 }