diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-05-27 02:08:33 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-05-27 02:08:33 +0400 |
commit | 300d3c27bfbb89b2e3aef0be04de3004afc2d4ff (patch) | |
tree | fe431ef74d87bf4a8af114b35011e4e6736eadd5 /misc | |
parent | ea68f9a5e6bcb52d7c82fbd43874b0283e3a95a1 (diff) |
Fixes #2900 Now reading 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_CF_CONNECTING_IP' and falling back to REMOTE_ADDR
Getting visitor IP via proxy script should now work!
This was also reported in: http://forum.piwik.org/read.php?2,115900
Diffstat (limited to 'misc')
-rw-r--r-- | misc/proxy-hide-piwik-url/piwik.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/misc/proxy-hide-piwik-url/piwik.php b/misc/proxy-hide-piwik-url/piwik.php index 1ebbf5d9b1..fa0d4f682f 100644 --- a/misc/proxy-hide-piwik-url/piwik.php +++ b/misc/proxy-hide-piwik-url/piwik.php @@ -61,7 +61,8 @@ if (empty($_GET)) { @ini_set('magic_quotes_runtime', 0); // 2) PIWIK.PHP PROXY: GET parameters found, this is a tracking request, we redirect it to Piwik -$url = sprintf("%spiwik.php?cip=%s&token_auth=%s&", $PIWIK_URL, @$_SERVER['REMOTE_ADDR'], $TOKEN_AUTH); +$url = sprintf("%spiwik.php?cip=%s&token_auth=%s&", $PIWIK_URL, getVisitIp(), $TOKEN_AUTH); + foreach ($_GET as $key => $value) { $url .= $key . '=' . urlencode($value) . '&'; } @@ -73,3 +74,20 @@ $stream_options = array('http' => array( )); $ctx = stream_context_create($stream_options); echo file_get_contents($url, 0, $ctx); + +function getVisitIp() +{ + $matchIp = '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/'; + $ipKeys = array( + 'HTTP_X_FORWARDED_FOR', + 'HTTP_CLIENT_IP', + 'HTTP_CF_CONNECTING_IP', + ); + foreach($ipKeys as $ipKey) { + if (isset($_SERVER[$ipKey]) + && preg_match($matchIp, $_SERVER[$ipKey])) { + return $_SERVER[$ipKey]; + } + } + return @$_SERVER['REMOTE_ADDR']; +} |