Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
65 righe
1.6 KiB
65 righe
1.6 KiB
<? |
|
if (!isset($_SERVER['PHP_AUTH_USER'])) { |
|
header("WWW-Authenticate: Basic realm=\"Private Area\""); |
|
header("HTTP/1.0 401 Unauthorized"); |
|
getResponse(["response"=>401,"description"=>"Unauthorized"]); |
|
exit; |
|
} else { |
|
|
|
if(!file_exists(__DIR__."/access.json")){ |
|
getResponse(["response"=>500,"description"=>"Internal Server Error"]); |
|
exit; |
|
} |
|
|
|
$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; |
|
include_once($configPath); |
|
$credential = json_decode(file_get_contents(__DIR__."/access.json"), true); |
|
|
|
if(DEMO_ENV){ |
|
|
|
$login = [ |
|
'demo' => true, |
|
'utente' => $credential['demo']['utente'], |
|
'password' => base64_decode($credential['demo']['password']) |
|
]; |
|
$cryptpassw = md5($_SERVER['PHP_AUTH_PW']); |
|
|
|
}elseif(!DEMO_ENV){ |
|
|
|
$login = [ |
|
'demo' => false, |
|
'utente' => $credential['produzione']['utente'], |
|
'password' => base64_decode($credential['produzione']['password']) |
|
]; |
|
$cryptpassw = md5($_SERVER['PHP_AUTH_PW']); |
|
|
|
}else{ |
|
getResponse(["response"=>500,"description"=>"Internal Server Error"]); |
|
die(); |
|
} |
|
|
|
if (($_SERVER['PHP_AUTH_USER'] != $login['utente']) || (password_verify($cryptpassw,$login['password']) == false) ) { |
|
header("WWW-Authenticate: Basic realm=\"Private Area\""); |
|
header("HTTP/1.0 401 Unauthorized"); |
|
getResponse(["response"=>401,"description"=>"Unauthorized"]); |
|
exit; |
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getResponse($responseError){ |
|
echo json_encode($responseError); |
|
die(); |
|
} |
|
|
|
?> |
|
|
|
|
|
|
|
|
|
|
|
|