Skip to content

Commit

Permalink
is_https() fixed for load balancers / reverse proxies;
Browse files Browse the repository at this point in the history
typo fixed in changelog
  • Loading branch information
azett committed Apr 27, 2024
1 parent 3659e5e commit 16298a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Under delevopment: [FlatPress 1.3.1](https://github.com/flatpressblog/flatpress/releases/tag/1.3.1)
# Under development: [FlatPress 1.3.1](https://github.com/flatpressblog/flatpress/releases/tag/1.3.1)
## Bugfixes
- HTTP-only Login wasn't possible under some circumstances ([#371](https://github.com/flatpressblog/flatpress/issues/371), [#378](https://github.com/flatpressblog/flatpress/issues/378))

Expand Down
23 changes: 14 additions & 9 deletions defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@

// supports Apache and IIS
$serverport = '';
var_dump(is_https());
if (is_https()) {
// HTTPS enabled
$serverport = "https://";
Expand Down Expand Up @@ -171,21 +172,25 @@
header('X-Frame-Options: SAMEORIGIN');
header('X-XSS-Protection: 1; mode=block');
header('X-Content-Type-Options: nosniff');
//
// End of send header
//

#function _dummy() {}
#set_error_handler('_dummy');



//
// End of send header
//

/**
* Checks if FlatPress is called via HTTPS.
*
* @return boolean <code>true</code> when FlatPress is called via HTTPS; <code>false</code> otherwise.
*/
function is_https() {
return (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on'));
// HTTPS called web server
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) {
return true;
}
// HTTPS called reverse proxy / load balancer
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
// none of the above: must be HTTP
return false;
}

1 comment on commit 16298a3

@Fraenkiman
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$isSecure = true; ?

Please sign in to comment.