LocatorHQ

Rob

Active Member
I'm not getting any info back from LocatorHQ, is anyone successfully using this extension?

Thanks
 
Hi

telize works.

I've had a look at the locatorhq API docs and I am not sure if this has any baring on why it isn't working but there are a couple of things:

In the file IpLocationLocatorhqExt.php there is this section:

$location = new IpLocation();
$location->ip_address = $trackModel->ip_address;
$location->country_code = strtoupper($response['countryCode']);
$location->country_name = ucwords(strtolower($response['countryName']));
$location->zone_name = !isset($response['region']) ? null : ucwords(strtolower($response['region']));
$location->city_name = !isset($response['city']) ? null : ucwords(strtolower($response['city']));
$location->latitude = (float)$response['latitude'];
$location->longitude = (float)$response['longitude'];

In the API docs some of these response params seem to be different to the above:

"regionName" For US/Canada this is the state value. For others this is the district/region value
"cityName" Auckland
"cityLattitude" Standard Lattitude
"cityLongitude" Standard Longitude

The issue that may well be causing my particular problem is the sending of the site/server IP address. My app is sat behind a firewall and load balancer which means my public IP is actually different to the one MW sees on its server. What would be the correct syntax to make MW send a particular IP?

$remoteUrl = 'http://api.locatorhq.com/?user=%s&key=%s&ip%s=&format=json';
$remoteUrl = sprintf($remoteUrl, $this->getOption('username'), $this->getOption('api_key'), $trackModel->ip_address);

I want to use LocatorHQ because in future I want to extend the MW extension so it pulls all the data they have such as OS, browser, device type etc. All very useful data for marketing purposes.
 
Have a look in apps/common/components/helpers/AppInitHelper.php in the fixRemoteAddress() method.
Do a print_r($_SERVER) and based on that output, see where the real ip address resides and alter fixRemoteAddress() accordingly.
 
No luck unfortunately. All very strange. Any other ideas?

I've sent new test campaigns after making the alterations, but does MW hold the IP info of all campaigns and retrospectively query a service like locatorhq if it is activated after a campaign is sent?
 
Yeah, the ips are stored in a table called ip_location so you should empty that table and try sending afterwards.
 
Cleared that, still the same.

Does this extension work for you?

Quite likely I didn't edit the appinithelper file correctly, is it these two lines that need changing?

} elseif (empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['MY_IP_HERE'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['MY_IP_HERE'];
 
Does this extension work for you?
I haven't tried it in a while, i'll find the time to do it though.

Quite likely I didn't edit the appinithelper file correctly, is it these two lines that need changing?

Currently the code is:
PHP:
public static function fixRemoteAddress()
{
    static $hasRan = false;
    if ($hasRan) {
        return;
    }
   
    if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
    } elseif (empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_REAL_IP'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
    } elseif (empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

    $hasRan = true;
}


You can make it:
PHP:
public static function fixRemoteAddress()
{
    static $hasRan = false;
    if ($hasRan) {
        return;
    }
   
    if (!empty($_SERVER['WHATEVER'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['WHATEVER'];
    } elseif (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
    } elseif (empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_REAL_IP'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
    } elseif (empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

    $hasRan = true;
}
Of course, replace $_SERVER['WHATEVER'] with whatever the part from $_SERVER tells you the real ip.
 
Back
Top