This commit is contained in:
Shish 2022-07-09 23:37:43 +01:00
parent 476808db4b
commit e97198aa10
3 changed files with 21 additions and 20 deletions

View File

@ -164,18 +164,20 @@ function check_im_version(): int
* Get request IP * Get request IP
*/ */
function get_remote_addr() { function get_remote_addr()
{
return $_SERVER['REMOTE_ADDR']; return $_SERVER['REMOTE_ADDR'];
} }
/** /**
* Get real IP if behind a reverse proxy * Get real IP if behind a reverse proxy
*/ */
function get_real_ip() { function get_real_ip()
{
$ip = get_remote_addr(); $ip = get_remote_addr();
if (REVERSE_PROXY_X_HEADERS && isset($_SERVER['HTTP_X_REAL_IP'])) { if (REVERSE_PROXY_X_HEADERS && isset($_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP']; $ip = $_SERVER['HTTP_X_REAL_IP'];
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$ip = "0.0.0.0"; $ip = "0.0.0.0";
} }
} }
@ -822,4 +824,3 @@ function generate_key(int $length = 20): string
return $randomString; return $randomString;
} }