Anyone using the Maxmind geoip lookup?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jakez
    Confirmed User
    • Jan 2004
    • 5656

    #1

    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..
    [email protected] - jakezdumb - 573689400

    Killuminati
  • andrej_NDC
    Registered User
    • May 2004
    • 7760

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

    Comment

    • SmellyNose
      Confirmed User
      • Aug 2009
      • 206

      #3
      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.
      I'm a PHP developer - 594086663 - [email protected]

      Comment

      • MasterM
        Confirmed User
        • Oct 2002
        • 248

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

        Comment

        • iSpyCams
          Amateur Gynecologist
          • May 2009
          • 4436

          #5
          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.
          - As soon as I think up a good sig it's going here.

          Comment

          • Barry-xlovecam
            It's 42
            • Jun 2010
            • 18083

            #6
            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?

            Comment

            • Davy
              Confirmed User
              • Apr 2006
              • 4323

              #7
              I will also load a probably huge file on every page load.
              Do yourself a favor and import the data into a database.
              ---
              ICQ 14-76-98 <-- I don't use this at all

              Comment

              • CrocMint
                Confirmed User
                • Oct 2010
                • 227

                #8
                Originally posted by Davy
                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.
                Our Herbal Supplements for Adult Health - a New Revenue Stream for You - mike[at]crocmint.com

                Comment

                • Kiopa_Matt
                  Confirmed User
                  • Oct 2007
                  • 1448

                  #9
                  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.
                  Last edited by Kiopa_Matt; 11-16-2010, 07:26 AM.
                  xMarkPro -- Ultimate Blog Network Management
                  Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more!

                  Comment

                  • Kiopa_Matt
                    Confirmed User
                    • Oct 2007
                    • 1448

                    #10
                    Originally posted by Davy
                    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.
                    xMarkPro -- Ultimate Blog Network Management
                    Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more!

                    Comment

                    • Jason Voorhees
                      So Fucking Banned
                      • Jul 2010
                      • 843

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

                      Comment

                      • myneid
                        Confirmed User
                        • Jan 2003
                        • 736

                        #12
                        best way to optimize maxmind is to use the apache module mod_geoip
                        Tanguy 0x7a69 inc. Programmer/President/CEO
                        http://www.0x7a69.com
                        A Leader in Programming since 1996
                        PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting

                        Comment

                        • borked
                          Totally Borked
                          • Feb 2005
                          • 6284

                          #13
                          Originally posted by Jason Voorhees
                          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 ...

                          For coding work - hit me up on andy // borkedcoder // com
                          (consider figuring out the email as test #1)



                          All models are wrong, but some are useful. George E.P. Box. p202

                          Comment

                          • borked
                            Totally Borked
                            • Feb 2005
                            • 6284

                            #14
                            Originally posted by Jakez
                            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....

                            For coding work - hit me up on andy // borkedcoder // com
                            (consider figuring out the email as test #1)



                            All models are wrong, but some are useful. George E.P. Box. p202

                            Comment

                            • Jakez
                              Confirmed User
                              • Jan 2004
                              • 5656

                              #15
                              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!
                              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...hp&cache=cache) opens as a corrupt 0kb file for me..?
                              [email protected] - jakezdumb - 573689400

                              Killuminati

                              Comment

                              • GrouchyAdmin
                                Now choke yourself!
                                • Apr 2006
                                • 12085

                                #16
                                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.

                                Comment

                                • Nasty
                                  Confirmed User
                                  • Aug 2002
                                  • 1575

                                  #17
                                  Originally posted by myneid
                                  best way to optimize maxmind is to use the apache module mod_geoip
                                  What he said

                                  “Ours is a world of nuclear giants and ethical infants. We know more about war than we know about peace, more about killing than we know about living. If we continue to develop our technology without wisdom or prudence, our servant may prove to be our executioner.” ― Omar Bradley (1948)

                                  Comment

                                  • gaffg
                                    Confirmed User
                                    • Jan 2010
                                    • 717

                                    #18
                                    I was asked about maxmind recently, seems popular
                                    http://gaffg.com/affiliate-programs/
                                    Find all gambling affiliate programs based on categories: casino, poker, sportsbetting, bingo, mobile.
                                    Find forex and binary options affiliate programs.
                                    Listed by revenue share, CPA and sub affiliate commission.

                                    Comment

                                    • borked
                                      Totally Borked
                                      • Feb 2005
                                      • 6284

                                      #19
                                      Originally posted by Jakez
                                      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...hp&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

                                      For coding work - hit me up on andy // borkedcoder // com
                                      (consider figuring out the email as test #1)



                                      All models are wrong, but some are useful. George E.P. Box. p202

                                      Comment

                                      • Jakez
                                        Confirmed User
                                        • Jan 2004
                                        • 5656

                                        #20
                                        Originally posted by borked
                                        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!
                                        [email protected] - jakezdumb - 573689400

                                        Killuminati

                                        Comment

                                        • KillerK
                                          Confirmed User
                                          • May 2008
                                          • 3406

                                          #21
                                          Originally posted by Davy
                                          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.

                                          Comment

                                          Working...