|
1 | | -# GeoIP for Laravel 4 - Alpha |
2 | | - |
3 | | -[](https://packagist.org/packages/torann/geoip) [](https://packagist.org/packages/torann/geoip) |
4 | | - |
5 | | -Determine the geographical location of website visitors based on their IP addresses. |
6 | | - |
7 | | ----------- |
8 | | - |
9 | | -## Installation |
10 | | - |
11 | | -- [GeoIP for Laravel 4 on GitHub](https://github.com/torann/laravel-4-geoip) |
12 | | - |
13 | | -To get the latest version of GeoIP simply require it in your `composer.json` file. |
14 | | - |
15 | | -~~~ |
16 | | -"torann/geoip": "dev-master" |
17 | | -~~~ |
18 | | - |
19 | | -You'll then need to run `composer install` to download it and have the autoloader updated. |
20 | | - |
21 | | -Once GeoIP is installed you need to register the service provider with the application. Open up `app/config/app.php` and find the `providers` key. |
22 | | - |
23 | | -~~~php |
24 | | -'providers' => array( |
25 | | - |
26 | | - 'Torann\GeoIP\GeoIPServiceProvider', |
27 | | - |
28 | | -) |
29 | | -~~~ |
30 | | - |
31 | | -GeoIP also ships with a facade which provides the static syntax for creating collections. You can register the facade in the `aliases` key of your `app/config/app.php` file. |
32 | | - |
33 | | -~~~php |
34 | | -'aliases' => array( |
35 | | - |
36 | | - 'GeoIP' => 'Torann\GeoIP\GeoIPFacade', |
37 | | - |
38 | | -) |
39 | | -~~~ |
40 | | - |
41 | | -Create configuration file using artisan |
42 | | - |
43 | | -~~~ |
44 | | -$ php artisan config:publish torann/geoip |
45 | | -~~~ |
46 | | - |
47 | | -## Usage |
48 | | - |
49 | | -Get the location data for a website visitor: |
50 | | - |
51 | | -```php |
52 | | -$location = GeoIP::getLocation(); |
53 | | -``` |
54 | | - |
55 | | -> When an IP is not given the `$_SERVER["REMOTE_ADDR"]` is used. |
56 | | -
|
57 | | -Getting the location data for a given IP: |
58 | | - |
59 | | -```php |
60 | | -$location = GeoIP::getLocation( '232.223.11.11' ); |
61 | | -``` |
62 | | - |
63 | | -### Example Data |
64 | | - |
65 | | -```php |
66 | | -array ( |
67 | | - "ip" => "232.223.11.11", |
68 | | - "isoCode" => "US", |
69 | | - "country" => "United States", |
70 | | - "city" => "New Haven", |
71 | | - "state" => "CT", |
72 | | - "postal_code" => "06510", |
73 | | - "lat" => 41.28, |
74 | | - "lon" => -72.88, |
75 | | - "timezone" => "America/New_York", |
76 | | - "continent" => "NA", |
77 | | - "default" => false |
78 | | -); |
79 | | -``` |
80 | | - |
81 | | -#### Note |
82 | | - |
83 | | -In the case that a location is not found the fallback location will be returned with the `default` parameter set to `true`. In a future release I'll make the default location customizable. For not it is New Haven, CT. |
84 | | - |
85 | | -## Services |
86 | | - |
87 | | - |
88 | | -### [MaxMind](http://www.maxmind.com) |
89 | | - |
90 | | -- **Database Service**: To use the database version of MaxMind services download the `GeoLite2-City.mmdb` from [http://dev.maxmind.com/geoip/geoip2/geolite2/](http://dev.maxmind.com/geoip/geoip2/geolite2/) and extract it to `/app/database/maxmind/`. And that's it. |
91 | | - |
92 | | - |
| 1 | +# GeoIP for Laravel 4 |
| 2 | + |
| 3 | +[](https://packagist.org/packages/torann/geoip) [](https://packagist.org/packages/torann/geoip) |
| 4 | + |
| 5 | +Determine the geographical location of website visitors based on their IP addresses. |
| 6 | + |
| 7 | +---------- |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +- [GeoIP for Laravel 4 on Packagist](https://packagist.org/packages/torann/geoip) |
| 12 | +- [GeoIP for Laravel 4 on GitHub](https://github.com/torann/laravel-hashids) |
| 13 | + |
| 14 | + |
| 15 | +To get the latest version of GeoIP simply require it in your `composer.json` file. |
| 16 | + |
| 17 | +~~~ |
| 18 | +"torann/geoip": "0.1.*@dev" |
| 19 | +~~~ |
| 20 | + |
| 21 | +You'll then need to run `composer install` to download it and have the autoloader updated. |
| 22 | + |
| 23 | +Once GeoIP is installed you need to register the service provider with the application. Open up `app/config/app.php` and find the `providers` key. |
| 24 | + |
| 25 | +~~~php |
| 26 | +'providers' => array( |
| 27 | + |
| 28 | + 'Torann\GeoIP\GeoIPServiceProvider', |
| 29 | + |
| 30 | +) |
| 31 | +~~~ |
| 32 | + |
| 33 | +GeoIP also ships with a facade which provides the static syntax for creating collections. You can register the facade in the `aliases` key of your `app/config/app.php` file. |
| 34 | + |
| 35 | +~~~php |
| 36 | +'aliases' => array( |
| 37 | + |
| 38 | + 'GeoIP' => 'Torann\GeoIP\GeoIPFacade', |
| 39 | + |
| 40 | +) |
| 41 | +~~~ |
| 42 | + |
| 43 | +Create configuration file using artisan |
| 44 | + |
| 45 | +~~~ |
| 46 | +$ php artisan config:publish torann/geoip |
| 47 | +~~~ |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +Get the location data for a website visitor: |
| 52 | + |
| 53 | +```php |
| 54 | +$location = GeoIP::getLocation(); |
| 55 | +``` |
| 56 | + |
| 57 | +> When an IP is not given the `$_SERVER["REMOTE_ADDR"]` is used. |
| 58 | +
|
| 59 | +Getting the location data for a given IP: |
| 60 | + |
| 61 | +```php |
| 62 | +$location = GeoIP::getLocation( '232.223.11.11' ); |
| 63 | +``` |
| 64 | + |
| 65 | +### Example Data |
| 66 | + |
| 67 | +```php |
| 68 | +array ( |
| 69 | + "ip" => "232.223.11.11", |
| 70 | + "isoCode" => "US", |
| 71 | + "country" => "United States", |
| 72 | + "city" => "New Haven", |
| 73 | + "state" => "CT", |
| 74 | + "postal_code" => "06510", |
| 75 | + "lat" => 41.28, |
| 76 | + "lon" => -72.88, |
| 77 | + "timezone" => "America/New_York", |
| 78 | + "continent" => "NA", |
| 79 | + "default" => false |
| 80 | +); |
| 81 | +``` |
| 82 | + |
| 83 | +#### Note |
| 84 | + |
| 85 | +In the case that a location is not found the fallback location will be returned with the `default` parameter set to `true`. In a future release I'll make the default location customizable. For not it is New Haven, CT. |
| 86 | + |
| 87 | +## Services |
| 88 | + |
| 89 | + |
| 90 | +### [MaxMind](http://www.maxmind.com) |
| 91 | + |
| 92 | +- **Database Service**: To use the database version of MaxMind services download the `GeoLite2-City.mmdb` from [http://dev.maxmind.com/geoip/geoip2/geolite2/](http://dev.maxmind.com/geoip/geoip2/geolite2/) and extract it to `/app/database/maxmind/`. And that's it. |
| 93 | + |
| 94 | + |
0 commit comments