IP to Country Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessy
    New Member
    • Oct 2006
    • 106

    IP to Country Problem

    Hi ,

    i need to get the country of the visitor of the site so i downloaded a DB of all the countries and their corresponding IPs but not in Dotted format ,
    but it fails to get my country although it's listed in the DB but seems the IP is not present in the DB ..
    i convert the IP using ip2long() function which generates 9 numbers ALthough all the IPs in the DB for my country are 10 numbers so the script fails to show my Country ...anyone have an answer for this ??
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    The format of the data you use in your search query must match the format of the data in your database, or the database will not return correct results (obviously).

    Therefore, you must know how the data in your database is formatted so you can convert the IP address of your visitors into that format.

    So the real question is: how is the data in the database formatted?
    Some examples would be good.

    Without that info there is little we can do to help you.

    Comment

    • jessy
      New Member
      • Oct 2006
      • 106

      #3
      Well, thats a sample of the CountryIp DB :
      Code:
      1358400256,1358400511,AFGHANISTAN
      3642070112,3642070127,AFGHANISTAN
      3650609920,3650610175,AFGHANISTAN
      3650610688,3650611455,AFGHANISTAN
      1347305472,1347309567,ALBANIA
      3252439552,3252439583,ALBANIA
      and the ReadMe File Says i should transform the Visitors IP using ip2long Function and when i do that i get a nine numberIP while all my Countries listed IPs are 10 digits !!

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Are you sure they are all 10 characters long?

        According to my tests, all IP addresses starting with 58 or less will be 9 chars.
        Parts of Japan should belong to that group. What does your DB say about that zone?

        You should also note that the because PHP's integers are signed, some of the long values given by the ip2long function will result in negative values, which is probably not what you want to be using.

        To get the actual unsigned long as a string, you can do something like:
        [code=php]
        $ulong = sprintf("%u", ip2long($ip));
        [/code]

        P.S.
        I deleted the duplicate post you made.

        Comment

        • jessy
          New Member
          • Oct 2006
          • 106

          #5
          Yeah, You're Right Japan are 9 digits :
          721420288,73819 7503,JAPAN
          anyway, i cant seem to find my country :(

          and Yes i Used this line exactly as you wrote :
          $ip = sprintf("%u", ip2long($ip));

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Your country isn't listed in the database?
            I would call that a rather large oversight :)

            Is there a change that there are parts of it missing?
            How did you set it up?

            Comment

            • jessy
              New Member
              • Oct 2006
              • 106

              #7
              NO Sir :D
              My Country is Listed But i Mean Listed in 10 Digits NOt 9 !!
              I Began To Doubt My IP :)
              i even checked it on Many Sites and Used an online Calculator to do that transformation thing

              Comment

              • xNephilimx
                Recognized Expert New Member
                • Jun 2007
                • 213

                #8
                hi jessy.
                I had the same problem, and another downside about downloading a db, is that you have to keep updating it if something changes.
                I use this now geoPlugin
                If you use curl (or even js), you can get info from their api, and it has a lot more and cool functionalities (like goelocation, for example -latitude, longitude-, so you can combine it with google/live/other maps).

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  In that case I would definitely not rely on that database to much.
                  Who knows how many other holes there are in the data.

                  You should give xNephilimx's idea a try

                  Comment

                  • jessy
                    New Member
                    • Oct 2006
                    • 106

                    #10
                    Okay, I followed The Steps at GeoPlugin and made my domain activated and added the li

                    Okay, I followed The Steps at GeoPlugin and made my domain activated and added the lines of the Js functions , but can you tell me how to call the country function

                    $countryName=ge oplugin_country Name();
                    coz this seems not working with me

                    Thanks Alot

                    <sorry for the title its a mistake >

                    Comment

                    • jessy
                      New Member
                      • Oct 2006
                      • 106

                      #11
                      Thank You So Much 'xNephilimx'

                      I Followed The Examples There and Everything is Working Great Now !

                      Comment

                      • xNephilimx
                        Recognized Expert New Member
                        • Jun 2007
                        • 213

                        #12
                        Originally posted by jessy
                        Thank You So Much 'xNephilimx'

                        I Followed The Examples There and Everything is Working Great Now !
                        Glad to read that!
                        I'm sorry I couldn't reply earlier, but I'm off any computers during weekends, XD

                        Comment

                        Working...