prepare('select count(*) as count, username from users where username = :username AND password = :password;'); $authStmt->bindValue(':username', $_SERVER['PHP_AUTH_USER']); $authStmt->bindValue(':password', $_SERVER['PHP_AUTH_PW']); $result = $authStmt->execute(); if ($result->fetchArray()[0] != 1) { unauthorized_die(); } return $_SERVER['PHP_AUTH_USER']; } function unauthorized_die() { header('Location: unauthorized.php'); die('Unauthorized'); }