SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Determine user's country

    What is the easiest way to determine a user's country?

    I want to add a feature to our e-commerce store that determines the user's country and provides the shipping cost. We only ship to the US/Canada with US getting a flat rate of $5.95 and Canada a flat rate of $15. So just figuring out the user's country we can display the correct flat rate shipping throughout their visit.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You need an IP-to-Location database, and need to keep it up to date as ISPs reallocate their IP space to different regions relatively often.

    MaxMind provides a free version (GeoLite Country and GeoLite City) that's around 90% accurate.

    Since they're never 100% accurate, and the user's current location isn't always where they want shipping to, you should still provide the ability for them to change the location you auto-detect.

  3. #3
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could ask them.

    You can also use a geoip database like http://www.maxmind.com/

    Best Regards, George

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This class can determining country of the network of a given IP address looking up a simple text database file.

    It can also determine the path of an image file of the flag of a given country.

    http://www.phpclasses.org/browse/package/2363.html

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Note that when you do an IP lookup you are looking up the location of your visitor's ISP or proxy server. You are not able to tell where they are located themselves.

    For example the ISP I use have their headquarters in Melbourne but provide internet across the whole of Australia - all Geo data for all their cusotmers regardless of where in Australia they are get reported as being in Melbourne.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Note that when you do an IP lookup you are looking up the location of your visitor's ISP or proxy server. You are not able to tell where they are located themselves.

    For example the ISP I use have their headquarters in Melbourne but provide internet across the whole of Australia - all Geo data for all their cusotmers regardless of where in Australia they are get reported as being in Melbourne.
    Actually, MaxMind says you are in Sydney.

    http://www.maxmind.com/app/lookup_city

    GeoIP databases track regional allocations of an ISP's IP space, not the location of the ISP.

    They are more than 90&#37; accurate to the city level -- that's accuracy in determining the true location of the user, not the ISP.

    These databases would be worthless if your assumption were true (over 100 million American households would map to one of three cities of their ISP's headquarters, for example) -- so it's good that this isn't the case.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Actually, MaxMind says you are in Sydney.

    http://www.maxmind.com/app/lookup_city

    GeoIP databases track regional allocations of an ISP's IP space, not the location of the ISP.

    They are more than 90% accurate to the city level -- that's accuracy in determining the true location of the user, not the ISP.

    These databases would be worthless if your assumption were true (over 100 million American households would map to one of three cities of their ISP's headquarters, for example) -- so it's good that this isn't the case.
    Obviously some programs are not using the right places to lookup their location data. The Secunia software security program running on my computer shows my location as Melbourne.

    Still Sydney is a long way off from where I live so it still isn't all that accurate even with the more accurate data.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u can always use google api to locate user's location....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •