Ip-to-country
This small package will let you easily use the
IP-to-Country Database.
You can
see a working demo here (home hosted server, not always up).
Archive contents :
- flags :
a folder with flags from a lot of countries, found on http://ip-to-country.webhosting.info/node/view/91
- create_db.bat :
a sample batch file to run PHP in console
- csv2mysql.php :
a file to convert the csv file into a MySQL table
- GNUGPL.txt :
The GNU General Public License :)
- install.bat :
a tiny batch file that launches the command prompt in the current folder
- ip-to-country.csv :
the ip2country database. You can get the latest update on http://ip-to-country.webhosting.info/
- ip2country.php :
the ip2country script
- iso_country_list.sql :
a database matching country codes and names. You can get the latest update on http://27.org/isocountrylist/
- mypage.php :
an example of integration into a page
- parameters.php :
a file where you put your MySQL parameters (login, password, database name, host)
Required : PHP and MySQL
Recommended : phpMyAdmin
Tested with : Apache/2.0.53 (Win32) - PHP/5.0.3 - MySQL 4.1.10a-nt
If you don't know how to install an Apache server on your Windows computer, see this tutorial :
-> Installing an Apache server on Windows <http://www.patheticcockroach.com/mpam4/index.php?p=32>
How to get it work if you have a direct access to your server on Windows (on Linux or Mac,
you'll have to find out by yourself how to do it without our batch files) :
1. Enter your database informations in parameters.php
2. Edit create_db.bat : enter the exact path to your php.exe file
3. Launch install.bat, type create_db.bat and hit enter : this fills the database
4. Remove all files except : mypage.php, parameters.php, ip2country.php and the flags folder
5. Load mypage.php in your browser and enter any IP to see its country
How to get it work if you don't have a direct access to your server :
1. Same as above
2. Edit csv2mysql.php :
--- After ---
include("parameters.php");
--- Add ---
set_time_limit(0);
3. Load csv2mysql.php in your browser. This will take some time and impose
heavy strain on the server : if you're on a shared hosting, maybe you should avoid running
this script or at least ask permission before
4. Same as above
5. Same as above
/*************************************************************************
* *
* This script uses the IP-to-Country Database to give the country *
* corresponding to an IP *
* *
* Copyright (C) 2006 PatheticCockroach *
* http://www.patheticcockroach.com *
* Version 1.0 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* You can also provide yourself with an online copy of the text: *
* <http://www.gnu.org/copyleft/gpl.html> *
* <http://www.gnu.org/copyleft/gpl.txt> *
* *
*************************************************************************/
!======> Change log <======!
2006-11-04 (1.0) :
- first release
Script listed @
Hotscripts.com