GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Anyone using the Maxmind geoip lookup? (https://gfy.com/showthread.php?t=997691)

Jakez 11-15-2010 11:15 PM

Anyone using the Maxmind geoip lookup?
 
This thing is just returning United States for every non-US IP I throw at it.. wtf?

<?php
include_once("geoip.inc");
$open = geoip_open("GeoIP.dat", GEOIP_STANDARD);
print geoip_country_code_by_addr($open, "62.41.77.63");
geoip_close($open);
?>

Should return DE for Germany but it says US from everything..

andrej_NDC 11-16-2010 01:43 AM

I will have to check some older sites to get you the proper code.

SmellyNose 11-16-2010 02:08 AM

Code:

$bad_country_codes = Array('CN', 'JP', 'TW');

require_once("geoip.inc");

$gi = geoip_open("/usr/share/GeoIP/GeoIP.dat", GEOIP_STANDARD);
$cc = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
if(in_array($cc, $bad_country_codes)) {
        exit;
}

The above is what I use on one of my websites, so it looks like you're doing it correctly.

Have you checked you're not giving it a US ip all the time?

You can go to maxmind.com and enter the IP there and it will tell you the location of the IP so you will be able to see whether you've given it a US ip or your code is wrong.

MasterM 11-16-2010 02:47 AM

i blocked out the following countries also : IR ID KR VE IN

iSpyCams 11-16-2010 04:33 AM

I just started using it recently, I wanted to block the Dominican Republic from some of my cascades but it keeps thinking the DR is Canada.

Barry-xlovecam 11-16-2010 06:32 AM

I use the Perl Binary;

Code:

#!/usr/bin/perl
####################################
#geo_ip_no.cgi
#Specific geo target
#
#
#
#
####################################
use CGI::Carp qw/fatalsToBrowser/;
use CGI qw/:standard/;

$addr ="$ENV{'REMOTE_ADDR'}";
$browser = $ENV{'HTTP_USER_AGENT'};
$geoip_file =  "/usr/share/geo_ip/GeoIP.dat";

print "Content-type: text/html\n\n";

$qstring = "$ENV{'QUERY_STRING'}";
        if ($qstring =~ s/[^a-zA-Z0-9\_]//g) {print qq~HUH???~;      exit;}

        use Geo::IP;

                        $gi = Geo::IP->open( $geoip_file,  GEOIP_STANDARD)||die"died opening";

                                                $country_code = $gi->country_code_by_addr($addr);


                        if ($country_code !~/(AA|BB|CC|DD|EE)/i){
                               
                                #INSERT
                               
                               
                               
                               
}#end geo ip

else{
        exit;
}

Similar variables to the PHP maybe you can see why you are getting that error?

Davy 11-16-2010 07:41 AM

I will also load a probably huge file on every page load.
Do yourself a favor and import the data into a database.

CrocMint 11-16-2010 09:06 AM

Quote:

Originally Posted by Davy (Post 17702899)
I will also load a probably huge file on every page load.
Do yourself a favor and import the data into a database.

I dont think importing in mysql will increase performance...
Mysql DB will be huge enough and searching mysql db will not take less resource than searching their dat file...

I'm using other method to opimize this - caching resolved countries for visitor IP's , so at least when single surfer is visiting page(s) with geo detection multiple times within day or two, it only searches .dat file once for him.

Kiopa_Matt 11-16-2010 09:24 AM

I use it all the time, and it works great. Try this instead:

Code:

<?php
include_once("geoip.inc");
include_once("geoipregionvars.php");

$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, "62.41.77.63");

$country_code = $record->country_code;
$state_code = $record->region;
$city_name = $record->city;

geoip_close($gi);
?>

Should work fine. :)

Kiopa_Matt 11-16-2010 09:25 AM

Quote:

Originally Posted by Davy (Post 17702899)
I will also load a probably huge file on every page load.
Do yourself a favor and import the data into a database.

No, don't do that. It works just fine as is, and no need to create a headache for yourself every time Maxmind released an upgrade.

Jason Voorhees 11-16-2010 10:19 AM

http://www.geoplugin.com/ Better, use it. Made by Borked, user here.

myneid 11-16-2010 10:22 AM

best way to optimize maxmind is to use the apache module mod_geoip

borked 11-16-2010 11:22 AM

Quote:

Originally Posted by Jason Voorhees (Post 17703310)
http://www.geoplugin.com/ Better, use it. Made by Borked, user here.

Code:

Geolocation results for 62.41.77.63:

*City: 
*Region: 
*Area Code: 0
*DMA Code: 0
*Country Name: Germany
*Country Code: DE
*Longitude: 9
*Latitude: 51
*Currency Code: EUR
 Currency Symbol: ?
 US$ Exchange Rate: 0.7354336098
(US$ was used here as the base currency.)
(This can be changed for lookups.)

At todays rate, US$100 will cost you ?73.54

Some places you may wish to visit near :

1:
        Place: Gemünden an der Wohra
        Country Code: DE
        Region: Hesse
        County:
        Latitude: 50.9666667
        Longitude: 8.9666667
        Distance (miles): 2.72
        Distance (km): 4.38
        Direction (degrees) 142.38
        Direction (heading) SE
2:
        Place: Allendorf bei Frankenau
        Country Code: DE
        Region: Hesse
        County:
        Latitude: 51.0666667
        Longitude: 8.9000000
        Distance (miles): 6.33
        Distance (km): 10.19
        Direction (degrees) 45.22
        Direction (heading) NE
3:
        Place: Hatzbach
        Country Code: DE
        Region: Hesse
        County:
        Latitude: 50.8833333
        Longitude: 9.0166667
        Distance (miles): 8.09
        Distance (km): 13.02
        Direction (degrees) 173.34
        Direction (heading) S
4:
        Place: Allendorf an der Landsburg
        Country Code: DE
        Region: Hesse
        County:
        Latitude: 50.9500000
        Longitude: 9.2166667
        Distance (miles): 10.04
        Distance (km): 16.16
        Direction (degrees) 102.8
        Direction (heading) ESE
5:
        Place: Neustadt
        Country Code: DE
        Region: Hesse
        County:
        Latitude: 50.8500000
        Longitude: 9.1166667
        Distance (miles): 11.54
        Distance (km): 18.57
        Direction (degrees) 146.31
        Direction (heading) SSE

nope, it didn't get the city, but did get the country and lat/lon ...

borked 11-16-2010 11:27 AM

Quote:

Originally Posted by Jakez (Post 17702212)
This thing is just returning United States for every non-US IP I throw at it.. wtf?

<?php
include_once("geoip.inc");
$open = geoip_open("GeoIP.dat", GEOIP_STANDARD);
print geoip_country_code_by_addr($open, "62.41.77.63");
geoip_close($open);
?>

Should return DE for Germany but it says US from everything..

is GeoIP.dat the actual location of the .dat file? Have you tried adding the full server path to the dat file? Sounds to me like it can't find that GeoIP.dat file....

Jakez 11-16-2010 06:01 PM

Tried filling in the full path and it still functions the same, totally weird it just says US for any IP I feed to it..

Thanks Borked the geoplugin works great! :thumbsup
I did have to copy and paste the PHP class source and save it that way because the Winrar download on there (http://www.geoplugin.com/_media/webs...&cache =cache) opens as a corrupt 0kb file for me..?

GrouchyAdmin 11-16-2010 06:10 PM

I can only assume you aren't hard coding the URL, as you seem to have managed to handle things properly.

Are you caching the page with some WP-Supercache or other shit? If you have /any/ form of caching on this, it's not going to re-execute depending on how you are calling it.

Nasty 11-16-2010 06:36 PM

Quote:

Originally Posted by myneid (Post 17703320)
best way to optimize maxmind is to use the apache module mod_geoip

What he said :thumbsup

gaffg 11-16-2010 06:54 PM

I was asked about maxmind recently, seems popular

borked 11-17-2010 12:05 AM

Quote:

Originally Posted by Jakez (Post 17704630)
I did have to copy and paste the PHP class source and save it that way because the Winrar download on there (http://www.geoplugin.com/_media/webs...&cache =cache) opens as a corrupt 0kb file for me..?

strange - it downloaded fine for me (mac) - try using the direct URL (none-cached)
http://www.geoplugin.com/_media/webs....class.php.tgz

or download from PHPClasses

the classes from either source will be more up to date than the source you copy/pasted

Jakez 11-17-2010 01:16 AM

Quote:

Originally Posted by borked (Post 17705133)
strange - it downloaded fine for me (mac) - try using the direct URL (none-cached)
http://www.geoplugin.com/_media/webs....class.php.tgz

or download from PHPClasses

the classes from either source will be more up to date than the source you copy/pasted

Still says it's corrupt. Maybe it's just me and someone else using Windows can try opening it.

Grabbed the one from phpclasses and it works fine just like the one I copy and pasted from your site. Thanks!

KillerK 11-17-2010 01:32 AM

Quote:

Originally Posted by Davy (Post 17702899)
I will also load a probably huge file on every page load.
Do yourself a favor and import the data into a database.

This is the worst advice anyone can follow.

You will take a HUGE performance hit going to mysql. Don't listen to Davy.


All times are GMT -7. The time now is 05:08 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc