@@ -63,7 +63,7 @@ function define_env($name, $default) {
63
63
$ file_readonly = true ;
64
64
$ file_css = array ();
65
65
$ user = "" ;
66
-
66
+ $ status_code_set = false ;
67
67
68
68
# Authentication
69
69
$ authenticated = !REQUIRE_AUTH ; // Automatically authenticated if authentication is not required
@@ -107,20 +107,22 @@ function define_env($name, $default) {
107
107
if (!$ authenticated ) {
108
108
$ message .= 'Authentication failed!\n ' ;
109
109
}
110
-
110
+
111
111
## Login
112
112
if ((isset ($ _GET ['login ' ]) and !$ authenticated )) {
113
113
// Force the browser to prompt for a username and password
114
+ http_response_code (401 );
114
115
header ('WWW-Authenticate: Basic realm="Enter your credencials to login" ' );
115
- header ( ' HTTP/1.0 401 Unauthorized ' ) ;
116
+ $ status_code_set = true ;
116
117
$ authenticated = false ;
117
118
}
118
119
119
120
## Logout
120
121
if (isset ($ _GET ['logout ' ]) and $ authenticated ) {
121
122
unset($ _SESSION ['session_started ' ]);
122
- $ authenticated = false ;
123
123
http_response_code (401 );
124
+ $ status_code_set = true ;
125
+ $ authenticated = false ;
124
126
}
125
127
// $redirect_url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'],'?'));
126
128
// header("Location: $redirect_url");
@@ -318,7 +320,9 @@ function define_env($name, $default) {
318
320
$ html = file_get_contents ($ publish_file );
319
321
320
322
if ($ html == false ) {
321
- http_response_code (404 );
323
+ if (!$ status_code_set )
324
+ http_response_code (404 );
325
+
322
326
$ html = <<<TEMPLATE404
323
327
<div class="text-center">
324
328
<h1 class="error">404</h1>
0 commit comments