feat(UrlShortner): add module
This commit is contained in:
parent
c677114e08
commit
8f492f2432
4 changed files with 144 additions and 22 deletions
24
utils.php
24
utils.php
|
|
@ -64,3 +64,27 @@ function deleteAllFiles($path) {
|
|||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function askAuth($authConfig) {
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
|
||||
{
|
||||
header("WWW-Authenticate: Basic realm=\"You need to provide user and passwd\"");
|
||||
http_response_code(401);
|
||||
echo "Authentification Required";
|
||||
exit();
|
||||
}
|
||||
$providedUsername = $_SERVER['PHP_AUTH_USER'];
|
||||
$providedPassword = $_SERVER['PHP_AUTH_PW'];
|
||||
$found = false;
|
||||
foreach ($authConfig as $username => $password) {
|
||||
if ($username === $providedUsername && $password == $providedPassword) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
header("WWW-Authenticate: Basic realm=\"Invalid auth\"");
|
||||
http_response_code(401);
|
||||
echo "Invalid authentification, try again";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue