From 6f142d6a77149dab677840a259db0219828ee009 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Mon, 31 Dec 2018 16:27:34 -0500 Subject: [PATCH] added HTTP_X_FORWARDED_FOR check because we are behind varnish proxy. --- controller/Session.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/controller/Session.class.php b/controller/Session.class.php index 5387dd2e..492f33b8 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -34,9 +34,9 @@ class Session static::setNamespace(static::NAMESPACE_DEFAULT, $oldSession); } - Response::addPostRenderCallback(function(){ + Response::addPostRenderCallback(function () { $site_visitor_id = key_exists(static::USER_ID, $_SESSION) ? $_SESSION[static::USER_ID] : ''; - $response = LBRY::logWebVisitor(static::SITE_ID, $site_visitor_id, $_SERVER['REMOTE_ADDR']); + $response = LBRY::logWebVisitor(static::SITE_ID, $site_visitor_id, static::getOriginalIp()); if (!is_null($response) && key_exists('data', $response) && key_exists('visitor_id', $response['data'])) { @@ -111,4 +111,9 @@ class Session { static::unsetNamespace(static::NAMESPACE_FLASH_REMOVE); } + + public static function getOriginalIp() + { + return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? null; + } }