https://github.com/danielholmes/ip-detect
Utility to work with MaxMind GeoIP Country IP CSV
https://github.com/danielholmes/ip-detect
Last synced: 8 months ago
JSON representation
Utility to work with MaxMind GeoIP Country IP CSV
- Host: GitHub
- URL: https://github.com/danielholmes/ip-detect
- Owner: danielholmes
- Created: 2013-08-19T01:37:46.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-08-19T01:48:57.000Z (almost 13 years ago)
- Last Synced: 2025-02-10T01:41:22.243Z (over 1 year ago)
- Language: PHP
- Size: 1.3 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Simple IP Address Detection
===========================
Reads in the Geolite database (CSV Format not binary) and detects if a given IP Address is within it.
For more information on the Geolite database see:
* [Home Page](http://dev.maxmind.com/geoip/legacy/geolite/)
* [Direct download link](http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip)
Usage
-----
For an example usage, see example.php. The general idea is that you would save a subset of the full
CSV database to ranges.csv and then use that. For example if I wanted to redirect all Australian
users to a different url I would do the following (where `GeoIPCountryWhois.csv` is the full
database):
1. `grep "Australia" GeoIPCountryWhois.csv >> ranges.csv`
2. Copy `ranges.csv` and `ip-detect.php` to your website
3. Use the following code at the top of your website files (or within your source code as needed):
```php
require_once(dirname(__FILE__) . '/ip-detect.php');
// Redirect the visitor if their IP is in ranges.csv
// i.e. Redirect the visitor if their IP is recognised as Australian
if (isInIpRanges($_SERVER['REMOTE_ADDR']))
{
header('Location: http://www.example.org/australian-site');
}
// Rest of website code
```
Running Tests
-------------
`php tests.php`