I’ve found a few posts that cover the server IP address showing up for every visitor and I understand servers being behind proxies / load balancers. I deal with the later so in my config.ini.php I have proxy_client_headers[] set as “HTTP_X_FORWARDED_FOR”.
However I’m using the the PHP API on one site (no alternative as I need to track a php php that outputs an image) and I’m getting the server IP. In the script I’m tracking the both REMOTE_ADDR and HTTP_X_FORWARDED_FOR have the right IP so it’s getting lost along the way somewhere.
Where can I look as I’m lost at the moment!
Cheers,
Adam
Ignore found this which I managed to completely miss before!
http://forum.piwik.org/read.php?2,53741
Ah no don’t ignore as I still seem to have a problem
iwikTracker::$URL = 'https://piwikdomain.com/';
$t = new PiwikTracker( $idSite = 1);
$t->setTokenAuth( 'authtoken here' );
$t->setIp( $_SERVER['HTTP_X_FORWARDED_FOR'] );
Doesn’t work but manually setting the ip, e.g. to
$t->setIp( '123.123.123.123' );
works fine.
Any hints?
works fine. I’ve tried REMOTE_ADDR too.
Ok it was HTTP_X_FORWARDED_FOR confusing things and me being a little slow. Just in case anyone else looks for it I solved it this way:
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip = $_SERVER['REMOTE_ADDR'];
$ip_array = explode(',', $ip);
$ip = $ip_array[0]; //gives first ip in array
$t->setIp($ip);