Question

I have installed the Net_Geo pear package on my PHP Server.

This is the code I am using,

getRecord($ip); // output echo "Single IP results:
"; echo "
";
    print_r($results);
    echo "
"; // example array of multiple IPs $arr_ips = array ( gethostbyname("www.google.com"), gethostbyname("www.heise.de"), gethostbyname("www.college.ch") ); // fetch information array from net_geo $results = $net_geo->getRecord($arr_ips); // output echo "Multiple IP results:
"; echo "
";
    print_r($results);
    echo "
"; ?>

But this piece of code is not displaying any results. I think this code is not working at all.

This is the Net_Geo Object

Net_Geo Object ( [cache_path] => /tmp/ [cache_ttl] => 30 [default_timeout] => 60 [default_caida_server] => http://netgeo.caida.org/perl/netgeo.cgi [default_hostip_server] => http://api.hostip.info/ [localizer_data] => ./demo.csv [service] => [cache_prefix] => netgeo [useragent] => PHP/NetGeo [useragent_version] => 1.0 [array_limit] => 100 [cache] => Cache_Function Object ( [expires] => 2592000 [caching] => 1 [gc_time] => 1 [gc_probability] => 1 [gc_maxlifetime] => 86400 [container] => Cache_Container_file Object ( [fileLocking] => [cache_dir] => /tmp/ [filename_prefix] => netgeo [entries] => Array ( )

                [total_size] => 0
                [max_userdata_linelength] => 257
                [preload] => 1
                [id] => 
                [group] => 
                [expires] => 0
                [cachedata] => 
                [userdata] => 
                [unknown] => 1
                [encoding_mode] => base64
                [highwater] => 2048000
                [lowwater] => 1536000
                [allowed_options] => Array
                    (
                        [0] => encoding_mode
                        [1] => highwater
                        [2] => lowwater
                    )

                [group_dirs] => Array
                    (
                    )

            )

        [_debug] => 
        [_default_error_mode] => 
        [_default_error_options] => 
        [_default_error_handler] => 
        [_error_class] => PEAR_Error
        [_expected_errors] => Array
            (
            )

    )

[netgeo_global] => netgeo_global
[useragent_string] => 
[default_server] => 
[last_target] => 
[applicationName] => 
[alternateServerUrl] => 

)

Thanks

Was it helpful?

Solution

The documentation page of Net_Geo::Net_Geo() says that :

The method accepts two parameters :

bool Net_Geo() ( string $applicationName = '' , string $alternateServerUrl = '' )

And those parameters are :

  • string $applicationName - Optional application name to use in UserAgent when polling Netgeo
  • string $alternateServerUrl - URL to Netgeo service script, will be set to "http://netgeo.caida.org/perl/netgeo.cgi" unless changed

You are not passing any of those parameters -- which means the default Netgeo service URL is used...

... And if you try to open it ( http://netgeo.caida.org/perl/netgeo.cgi ), you'll see it doesn't work ; my Firefox says it cannot connect to the server.

This probably explains why your code doesn't produce any expected output : if it relies on a geolocalition server, and that server doesn't work anymore...


As a sidenote : according to the index of pear packages in the Networking section, Net_Geo is not maintained anymore, and the last version was released in 2006-03-29 ; which is quite not a good sign...

If you can install PECL packages (you'll probably need to be admin of your server), maybe the GeoIP package would interest you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top