Solved

World countries, state, city database

Posted on 2011-09-26
3
900 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 109

Accepted Solution

by:
Ray Paseur earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

831 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