Results 1 to 16 of 16
  1. #1
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037

    IP address location lookup?

    Anybody know how to take an IP in PHP and lookup its location (city, country)?

    whois.sc does it, and i'd like to have this added to our ordering process.

    We already have the IP being logged to $ip but it would be nice to take this and lookup the location for comparing with address of card holder?

    Thanks for any help in advance...
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  2. #2
    Join Date
    Apr 2005
    Posts
    42

  3. #3
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    I am starting to hate phpclasses.org...

    too much advertising, login and sloww...

    I personally use a database version:

    PHP Code:
    <?
    function check_country($ip){
        
    $ip sprintf("%u"ip2long($ip));
        
    $country 'other';
        
        
    $check_country = @mysql_query("SELECT `country`,`a2`,`a3`,`number` FROM `country_ip_list` WHERE `ipfrom` <= '$ip' and `ipto` >= '$ip' LIMIT 0, 1");

        if(
    $get_country = @mysql_fetch_row($check_country)){
            
    $country $get_country[0];
        }
        return 
    $country;
    }
    ?>
    I'll try to attach the sql file, otherwise I will post it as an online lesson :p (file too big)

    pm me and i'll email it to you throu yousendit.com

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  4. #4
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    Anyone else interested in downloading the database file:

    http://s25.yousendit.com/d.aspx?id=3...D1Q07OIH3RJK60

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  5. #5
    Join Date
    Apr 2003
    Location
    Sunny UK
    Posts
    33
    http://www.ip2nation.com/ for the DB and sample scripts.

    If you just want to display a users country on your site without the need to set up the DB tables, check out http://www.ipcatch.com/webmasters.php

  6. #6
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037
    Thanks for all the help guys. This is all I needed!
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  7. #7
    ip2nation.com
    But available in certain country only

  8. #8
    visit dnstuff.com

  9. #9
    Join Date
    Dec 2003
    Location
    Miami, FL
    Posts
    3,262
    I would only try to get the country (which is easy), getting the city isn't always accurate as the IP may be registered elsewhere.

  10. #10
    Join Date
    Jun 2004
    Location
    Bay Area -USA
    Posts
    1,738
    Thanks azizny! :-D Thats awesome.
    <<< Please see Forum Guidelines for signature setup. >>>

  11. #11
    Works like a charm

  12. #12
    Is there any way to lookup the region like west coast / east coast... or maybe the timezone?

  13. #13
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    Originally posted by legacy616
    Is there any way to lookup the region like west coast / east coast... or maybe the timezone?
    for the us or whole world?

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  14. #14
    just the United States... we have a regional website.. we would like to figure out who is outside of the Los Angeles/California area

  15. #15
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    ok...

    an open source databse with contains the long/lats:

    http://sourceforge.net/projects/zips/

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  16. #16
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082

Posting Permissions

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