Topic: [release] IP Geolocation

This extension will display the geographic location of users on their profile to administrators. It determines the geographic location based on the users IP address, using the free geoPlugin web service.

Changelog

  • ver 1.2 "Geolocate" link to fetch geolocation of users who registered before the extension was installed.

  • ver 1.1 Uses cURL if available, and includes some other small improvements.

  • ver 1.0 Initial release

Download

Screenshots
Profile of user before geolocation has been fetched
http://www.u-d-s.com/resources/punbb/screenshot1.png

Profile of user after geolocating
http://www.u-d-s.com/resources/punbb/screenshot2.png

Last edited by Justice (2009-11-11 04:42:50)

Re: [release] IP Geolocation

Good Extension, This was what I needed cool

Re: [release] IP Geolocation

Thx for ext. - I'm running on 1.3.2 / 1.3.4 and get this.... when registering new user

Warning: file_get_contents() [function.file-get-contents.php]: URL file-access is disabled in the server configuration in /home/..../register.php(225) : eval()'d code on line 29

Warning: file_get_contents(http://www.geoplugin.net/php.gp?ip=2xx.1xx.1xx.xx) [function.file-get-contents.php]: failed to open stream: no suitable wrapper could be found in /home/...../register.php(225) : eval()'d code on line 29

(1.3.2 above)

same error in 1.3.4 but on line 24 not 29 .....
(xx in ip added by me)

EDIT: guess my host has this PHP function called Http wrapper disabled... any workaround?

Re: [release] IP Geolocation

KeyDog wrote:

EDIT: guess my host has this PHP function called Http wrapper disabled... any workaround?

Can you check if your host allows cURL? I can make the extension check for either file_get_contents support or cURL support, and use whichever is available.

You can test for both of these functions like this:

if ( function_exists('curl_init')) {
   echo('cURL supported');
} else if ( ini_get('allow_url_fopen')) {
   echo('file_get_contents supported');
} else {
   echo('Neither cURL or file_get_contents supported. Sorry.');
}

Last edited by Justice (2009-11-04 19:22:08)

Re: [release] IP Geolocation

Hey
I tried what that code you suggested and turns out my host has cURL (cURL supported)

so; do I need to change this:
<hook id="rg_register_pre_add_user"><![CDATA[
            $geo_location = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$user_info['registration_ip']));

to this ?

<hook id="rg_register_pre_add_user"><![CDATA[
            $geo_location = unserialize(cURL('http://www.geoplugin.net/php.gp?ip='.$user_info['registration_ip']));


thx again

Re: [release] IP Geolocation

No, the code for using cURL will not be as simple as a function call. I think I'm actually going to update the extension to use the GeoPlugin PHP class, which will handle the cURL and file_get_contents() checking, and should simplify the extension code a bit.

In the meantime, if you simply want to get the current extension working with cURL, you can do the following:

Change

$geo_location = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$user_info['registration_ip']));

to

$geoplugin_host = 'http://www.geoplugin.net/php.gp?ip='.$user_info['registration_ip'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $geoplugin_host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geo_response = curl_exec($ch);
curl_close ($ch);

$geo_location = unserialize($geo_response);

Last edited by Justice (2009-11-05 19:56:45)

Re: [release] IP Geolocation

Thx that worked, no warnings on registration any more;
however when I'm on the new users profile (as admin)
I get this on bottom of page:

cURL supported Notice: Undefined variable: cur_post in /.../profile.php(1588) : eval()'d code on line 10

Don't worry about it too much if you're working on a improved release anyway...

Re: [release] IP Geolocation

Actually, PunBB has the get_remote_file(...) function. It uses curl or sockets if enabled.

You may use this function in your extensions.

Re: [release] IP Geolocation

Parpalak wrote:

Actually, PunBB has the get_remote_file(...) function. It uses curl or sockets if enabled.

You may use this function in your extensions.

Wow, thanks Parpalak, that is great to know. I was about to write a fsockopen() implementation to fall back on, but you just saved me the trouble!

Re: [release] IP Geolocation

Ok, version 1.1 is available (see my original post above for download). This version uses PunBB's built in get_remote_file() function as Parpalak suggested. Suggestions and other feedback welcome.

Re: [release] IP Geolocation

Version 1.2 available. This version displays a "Geolocate" link which allows you to populate the geolocation for preexisting users.

Last edited by Justice (2009-11-11 04:40:13)

Re: [release] IP Geolocation

excellent work works very well the new version  big_smile

Re: [release] IP Geolocation

Works like a charm now for me. Thx.