Skip to content

Commit 33720a4

Browse files
committed
Fix HTTP status code
1 parent 95181a3 commit 33720a4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

index.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function define_env($name, $default) {
6363
$file_readonly = true;
6464
$file_css = array();
6565
$user = "";
66-
66+
$status_code_set = false;
6767

6868
# Authentication
6969
$authenticated = !REQUIRE_AUTH; // Automatically authenticated if authentication is not required
@@ -107,20 +107,22 @@ function define_env($name, $default) {
107107
if(!$authenticated) {
108108
$message .= 'Authentication failed!\n';
109109
}
110-
110+
111111
## Login
112112
if((isset($_GET['login']) and !$authenticated)) {
113113
// Force the browser to prompt for a username and password
114+
http_response_code(401);
114115
header('WWW-Authenticate: Basic realm="Enter your credencials to login"');
115-
header('HTTP/1.0 401 Unauthorized');
116+
$status_code_set = true;
116117
$authenticated = false;
117118
}
118119

119120
## Logout
120121
if(isset($_GET['logout']) and $authenticated) {
121122
unset($_SESSION['session_started']);
122-
$authenticated = false;
123123
http_response_code(401);
124+
$status_code_set = true;
125+
$authenticated = false;
124126
}
125127
// $redirect_url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'],'?'));
126128
// header("Location: $redirect_url");
@@ -318,7 +320,9 @@ function define_env($name, $default) {
318320
$html = file_get_contents($publish_file);
319321

320322
if($html == false) {
321-
http_response_code(404);
323+
if(!$status_code_set)
324+
http_response_code(404);
325+
322326
$html = <<<TEMPLATE404
323327
<div class="text-center">
324328
<h1 class="error">404</h1>

0 commit comments

Comments
 (0)