Module

Archived
Forum
(read-only)


For official support, visit the official support site »

Geofinder

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Tom Jaeger

     

URL file-access is disabled in the server configuration AND allow_url_fopen = off

General

nevsie
nevsie

Many shared hosting environments will be configured like this… Especially as by default PHP 5 is shipping with allow_url_fopen set to off. This means this script will fail - through no fault of its own, just security measures many hosts would insist upon.

Many hosts will allow you to override this setting via a php.ini file, or a .htaccess file, or even by setting this value within PHP - 1and1 will not (surprise!).

Therefore, i came across this nice little function which i have used in the following way to make this all work…

1. add this new function to the bottom of mod.geofinder.php
REPLACE

return $query;
    
}

}
// END CLASS

?> 

WITH

return $query;
    
}

    
function curl_get_contents($url$timeout=60)
    
{
        $timeout 
abs((int)$timeout);
        
$curl curl_init();
        
$opts = array(
          
CURLOPT_URL => $url,
          
CURLOPT_RETURNTRANSFER => true,
          
CURLOPT_TIMEOUT => $timeout
        
);
        
curl_setopt_array($curl$opts);
        
$result curl_exec($curl);
        if(
$result === false)
        
{
          user_error
(curl_error($curl));
          return 
false;
        
}
        $response 
curl_getinfo($curlCURLINFO_HTTP_CODE);
        if(
$response != 200)
        
{
          user_error
("Received HTTP response of $response.");
        
}
        
return $result;
    
}


}
// END CLASS

?> 

THEN… at around line 765 of the mod.geofinder.php file:
REPLACE

$xml simplexml_load_file($request_url) or FALSE

WITH

// $xml = simplexml_load_file($request_url) or FALSE;
$mygeostring $this->curl_get_contents($request_url);
$xml simplexml_load_string($mygeostring) or FALSE

And… well it worked for me… hopefully might save someone else some time, N

Jason Ferrell
# 1
Jason Ferrell

As of Geofinder 2.1 (released March 22, 2011) cURL support is now the preferred way of communicating with Google’s Geocoding Service, with fallback to simplexml_load_file.