-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProxyHelper.php
More file actions
35 lines (32 loc) · 1.05 KB
/
ProxyHelper.php
File metadata and controls
35 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Proxy Helper Class
*
* This class adjusts the `$_SERVER` superglobal to reflect the original client's
* IP address and the correct SSL status. It is intended for use when the
* application is running behind a trusted reverse proxy.
*/
class ProxyHelper {
/**
* Executes the helper logic.
*
* It corrects the client's IP address by using the `HTTP_X_REAL_IP` header,
* and it corrects the SSL status by using the `HTTP_X_FORWARDED_PROTO` header.
*
* @return void
*/
public function run() {
// Set IP correctly when being proxied.
// Overwrites REMOTE_ADDR with the client IP provided by the proxy in HTTP_X_REAL_IP.
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}
// Set SSL Status correctly when being proxied.
// Checks if the request was originally made over HTTPS.
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['REQUEST_SCHEME'] = 'https';
$_SERVER['protossl'] = 's';
}
}
}