Display Viewer's Location

Discussion in 'PHP' started by addedtraffic, Mar 30, 2008.

  1. #1
    Anyone know of a php script that will display a users location and print it out to them?
     
    addedtraffic, Mar 30, 2008 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Do you just want the country or do you want to go all the way down to city?
     
    stephan2307, Mar 31, 2008 IP
  3. samser_m

    samser_m Well-Known Member

    Messages:
    990
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Generally, according to IP if you want to show country then you may get it from net searching on google.
     
    samser_m, Mar 31, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    You need to look for an IP to (Country/City/etc.) script. There are a number of free and paid scripts, API's, and database dumps out there depending on how accurate you need the info to be.
     
    jestep, Mar 31, 2008 IP
  5. addedtraffic

    addedtraffic Peon

    Messages:
    250
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the info guys!
     
    addedtraffic, Apr 1, 2008 IP
  6. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't know why people always go to the database solution when it comes to it.

    I recommend MaxMind GeoIP solution, a binary file + an api class that they provide freely.

    I think the binary file solution is better than DB because it's easier to update (they release an update every month) and takes much less space.

    You can find it at http://www.maxmind.com/app/geolitecountry
     
    mulari, Apr 1, 2008 IP
  7. addedtraffic

    addedtraffic Peon

    Messages:
    250
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Now thats what i call helpful!

    Thanks exactly what i was looking for!

    +Rep
     
    addedtraffic, Apr 1, 2008 IP
  8. addedtraffic

    addedtraffic Peon

    Messages:
    250
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Its not letting me rep...?
     
    addedtraffic, Apr 1, 2008 IP
  9. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?
    if (getenv(HTTP_X_FORWARDED_FOR)) {
    $ip_address = getenv(HTTP_X_FORWARDED_FOR);
    } else {
    $ip_address = getenv(REMOTE_ADDR);
    }
    ?>

    You can get the Ip address from this code, after that got a IP number and then find a country.
     
    singh.ajit05, Apr 2, 2008 IP
  10. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I don't want to get picky, as sometimes people right code fast on comments, but I still would like to comment that although the above code works it will still produce Notice errors.

    It's important to use ' when using strings to avoid all errors. If you want better code you should always show E_NOTICE errors as well and make sure to avoid them.

    So the above code should look like:
    And a small clarification about it, what it does is to also give you the real IP in-case the user is using a proxy.
     
    mulari, Apr 2, 2008 IP
  11. addedtraffic

    addedtraffic Peon

    Messages:
    250
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks for all the help guys!
     
    addedtraffic, Apr 2, 2008 IP