Created
October 4, 2017 21:46
-
-
Save naosim/3d2d1f825baa6e533c238b86fceea82e to your computer and use it in GitHub Desktop.
BasicAuth.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function basic_auth_custom(Closure $auth) { | |
switch (true) { | |
case !isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']): | |
case !$auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); | |
header('WWW-Authenticate: Basic realm="Enter username and password."'); | |
header('Content-Type: text/plain; charset=utf-8'); | |
die('このページを見るにはログインが必要です'); | |
} | |
} | |
function basic_auth(string $id, string $pw) { | |
basic_auth_custom(function(string $inputId, string $inputPw) use ($id, $pw) { | |
return $inputId === $id && $inputPw === $pw; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment