Hi... I'd like my web page to print the visitors city/state when they arrive at my site. I've seen script that show a person's COUNTRY via IP, but none that prints a person's city. Well, none that have worked.

For example, I did find an article http://www.linuxjournal.com/article/7856?page=0,0 about geolocation. That page gave me a lot more info than I needed - I Just wanted the city/state part.

Anyway, that script on the page didn't do anything. So, I wanted to know if anyone knew of a script. Thank you very much in advance.

Sam

    Search forum for:
    - geo
    - location
    - geolocation

    We have helped on guy a week ago.
    He now has a working geo location city script. Code is in end of his topic.

    His script uses one http://www.hostip.info/ service,
    basically:

    <?php
    
    // here we need to test if there really is one remote_address
    // before we do this:
    $ip = $_SERVER['REMOTE_ADDR'];
    
    $url = "http://api.hostip.info/get_html.php?ip=$ip";
    $info_geo = file_get_contents($url);
    
    // here we need to test if there is actually a good result in $info_geo
    // before display:
    echo $info_geo;
    
    exit(); // end this php script
    ?>

    More about hostip.info API : http://www.hostip.info/use.html
    🙂

      Thank you very much for the post. I tried all of these. They either didn't work or only the country part worked "You're in the UNITED STATES".

      But, nothing for city "you're in LOS ANGELES" or similar.

      The reason is I recall an promotion someone did a couple years ago where the headline of the ad said "Man in YOUR CITY discover how to blah, blah"

      Where "YOUR CITY" was the user's city. So, it would say "Man in Los Angeles discover how to ..." and because of that headline, the conversions of that site went up like 200%.

      I was told it was a simple PHP script that based on the user's IP, and it would print the city. It all seemed pretty simple and now that I'm searching for it, I've had zero luck. Only the a few script to print out the country, but nothing else =(

        You could try searching Google for "IP to city database".

          halojoy;10943552 wrote:

          We have helped on guy a week ago.
          He now has a working geo location city script. Code is in end of his topic.

          I looking for similar also, that show city and country. Only example I fund that show my city correct is http://www.hostip.info/use.html (same site that halojoy linked to)

          Don’t know exactly how to use it and if there is possible to have info in database? Like ip-to-country http://ip-to-country.webhosting.info/node/view/6?XID=33a51ea18d83e919c8624cec93786e1d

          Halojoy, can you link to that topic?

            16 days later
            kurosaki;10945476 wrote:

            You can check out the webmaster tools provided by IP2Location.com , you just need to copy and paste the codes onto your web page.

            http://www.ip2location.com/demo.aspx

            Or if you want a javascript based one, you can get the API from http://www.iplocationtools.com/api.html .

            None of this show my city correct, instead it show my ISP as city. First part of my complete ISP name.

            Only I found that work and show my city correct is http://www.hostip.info/use.html but don’t know how to use it.

            I don’t understand that guide

              Host ip couldn't find my city/state

                Write a Reply...