Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Access-Control-Allow-Origin: *");
- header("Access-Control-Allow-Headers: access");
- header("Access-Control-Allow-Methods: GET");
- header("Access-Control-Allow-Credentials: true");
- header('Content-Type: application/json');
- header('Cache-Control: no-cache');
- header("Authorization: Basic " . base64_encode('username:password')); // je tohle vubec treba?
- require '../../myautoload.php';
- require '../../vendor/autoload.php';
- use app\manager;
- use app\model;
- if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { //nemělo by se to spíš brát z hlavičky Authorizaion?
- $auth = new model\Model_Authenticator();
- $db = $auth->verifyAndReturnDatabase($_SERVER['PHP_AUTH_USER'], $_SERVER["PHP_AUTH_PW"]); // neměl bych nějak trimovat tyhle hodnoty
- if($db) {
- $devices = new manager\Manager_Devices($db);
- $devices->load();
- if($_GET["id"] ?? null && is_int($_GET["id"])) {
- print_r(json_encode($devices->get($_GET["id"])));
- }
- else {
- print_r(json_encode($devices->table()));
- }
- header('HTTP/1.0 200 OK');
- exit;
- }
- else {
- header('WWW-Authenticate: Basic realm="My Realm"');
- header('HTTP/1.0 401 Unauthorized');
- exit;
- }
- }
- else {
- header('WWW-Authenticate: Basic realm="My Realm"');
- header('HTTP/1.0 401 Unauthorized');
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement