Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

World countries, state, city database

Posted on 2011-09-26
3
Medium Priority
?
931 Views
Last Modified: 2012-05-12
I want to develop a website where user needs to enter his details like country, state, and city. where can I find such database and how can I implement that in php and mysql.

Just like http://www.datingplace.com/servlet/NewRegistration
0
Comment
Question by:sriramvemaraju2000
3 Comments
 
LVL 3

Expert Comment

by:anjos
ID: 36600279
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36600411
Anjos found a good site.  Implementation depends on the nature of the database you acquire.  If they offer the database in CSV or XML format, PHP has built in ways to process.  Then you simply create a mySQL table and you are off to the races.

If you need help with any of those steps, then please specifically ask about the specific step.  (Of note, it's foolish to help you with importing an XML file if you get a CSV file.)
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 36600480
This article shows how to translate the client's IP address to their country using the MaxMind data.  I believe that that file is free, whereas the more detailed files, giving all of country, state and city cost something.  You might want to consider a subscription, since the IP address blocks change sometimes.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_3437-IP-Address-to-Country-in-PHP.html

You might also be able to use a service like GEOIO.  Note line 10 of the code snippet.  The API key is free but rate-limited.  For a little money you can raise the rate limitations.  You can test the script on my server here.
http://www.laprbass.com/RAY_geoio_example.php

I use GEOIO to draw the map on this page.
http://www.landonbaseball.com/site_visitors.php

HTH, ~Ray
<?php // RAY_geoio_example.php
error_reporting(E_ALL);


// GET INFORMATION ABOUT YOUR SITE VISITORS LOCATION FROM GEOIO.COM
// MAN PAGE: http://www.iana.org/numbers/


// THIS IS THE URL FOR THE API
$key = ' -- GET YOUR OWN API KEY -- ';
$url = "http://api.geoio.com/q.php?key=$key&qt=geoip&d=pipe&q=";

// THIS IS THE CLIENT IP ADDRESS (ALMOST ALWAYS)
$ipa = $_SERVER["REMOTE_ADDR"];
$dat = file_get_contents($url . $ipa);
$inf = explode('|', $dat);

// SHOW WHAT WE GOT
echo "<pre>";
echo PHP_EOL . "CITY: $inf[0] ";
echo PHP_EOL . "STATE: $inf[1] ";
echo PHP_EOL . "COUNTRY: $inf[2] ";
echo PHP_EOL . "CARRIER: $inf[3] ";
echo PHP_EOL . "LAT: $inf[4] ";
echo PHP_EOL . "LON: $inf[5] ";

// SHOW A GOOGLE MAP OF WHAT WE GOT
$lnk = "<a target='_blank' href='http://maps.google.com/maps?f=q&source=s_q&hl=en&q=$inf[4],$inf[5]'>MAP: $inf[4],$inf[5]</a>";
echo PHP_EOL . $lnk;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question