GithubHelp home page GithubHelp logo

torann / laravel-geoip Goto Github PK

View Code? Open in Web Editor NEW
2.1K 62.0 371.0 159 KB

Determine the geographical location of website visitors based on their IP addresses.

Home Page: http://lyften.com/projects/laravel-geoip

License: BSD 2-Clause "Simplified" License

PHP 100.00%

laravel-geoip's Introduction

laravel-geoip's People

Contributors

acidjazz avatar alies-dev avatar butochnikov avatar dotpack avatar dwightwatson avatar dylan-dpc avatar evaldas-leliuga avatar faustbrian avatar highstrike avatar hughsaffar avatar irtaza100 avatar jalmatari avatar janicerar avatar jessarcher avatar kelvyncarbone avatar kyranb avatar lloricode avatar luket avatar mikemand avatar ncla avatar omranic avatar osmhub avatar phoenixpeca avatar rafalpietrzakio avatar rjp2525 avatar sakalauskas avatar samuelnitsche avatar torann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-geoip's Issues

Error on installation - class not found

Hi there.

I am getting an error when running php artisan: publish:

[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Torann\GeoIP\GeoIPServiceProvider' not found

However I am following the steps to install for Laravel 5

Any possible ideas what could be the cause?

Thanks!

M

GeoLite2-City.mmdb Not working in Laravel 5

Hi, I'm using Laravel 5.0.32. I've follow the installation step and download GeoLite2-City.mmdb to put at my /database/maxmind folder, however it keep returned default_location when I called GeoIP::getLocation() in my project.
contactcontroller_php_-serbapay_com-___dropbox_www_serbapay_com

I've seted type to database in config file, show as picture :
config_geoip_php_-serbapay_com-___dropbox_www_serbapay_com

please correct me if I wrong, thanks.

Can't get it to work with Laravel 5.1

Hi everyone,

I'm having some trouble in setting this up with Laravel 5.1 on a live server, I'm always getting the output below. I've already installed https://github.com/maxmind/MaxMind-DB-Reader-php but still can't get it to work properly.

Any help would be appreciated. Thanks.

RuntimeException in Decoder.php line 259:
The gmp or bcmath extension must be installed to read this database.
in Decoder.php line 259
at Decoder->decodeBigUint('V9=�', '4') in Decoder.php line 132
at Decoder->decodeByType('uint64', '38296851', '4') in Decoder.php line 98
at Decoder->decode('38296849') in Decoder.php line 194
at Decoder->decodeMap('9', '38296778') in Decoder.php line 105
at Decoder->decodeByType('map', '38296778', '9') in Decoder.php line 98
at Decoder->decode('38296777') in Reader.php line 65
at Reader->__construct('/var/www/ubicoding/frontend/releases/20151104205426/storage/app/geoip.mmdb') in Reader.php line 52
at Reader->__construct('/var/www/ubicoding/frontend/releases/20151104205426/storage/app/geoip.mmdb') in GeoIP.php line 181
at GeoIP->locate_maxmind('84.90.35.43') in GeoIP.php line 158
at GeoIP->find(null) in GeoIP.php line 119
at GeoIP->getLocation() in Facade.php line 211
at Facade::__callStatic('getLocation', array()) in StatisticsLibrary.php line 33
at GeoIPFacade::getLocation() in StatisticsLibrary.php line 33
at StatisticsLibrary::addStatistic(null, 'public', 'show', 'home') in HomeController.php line 32
at HomeController->index()
at call_user_func_array(array(object(HomeController), 'index'), array()) in Controller.php line 256
at Controller->callAction('index', array()) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(HomeController), object(Route), 'index') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(HomeController), object(Route), object(Request), 'index') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\HomeController', 'index') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 55

Make saving to session optional

Would it be possible to make saving to session optional?

If you're trying to test by switching with a VPN or something there's no way to clear that data without clearing all cookies/sessions.

IPv6 compatible

Hi,
I'm upgrading my L4 project and i would like to use this package. However, i wonder if it supports ipv6 detection?

Thanks

IP returning not found, but maxmind code working

Tried using this, got it all installed and thought it was working ok. When I tried a near by IP address it came up as not found. So I tried the other plugin I had installed https://github.com/smalldogs/ip2country
noticed it recognized the IP address. So i went ahead and installed maxmind directly https://github.com/maxmind/GeoIP2-php to see what happens and even this identifies the correct country code, I have pointed both this plugin and maxmind to use the same mmdb file, so can't understand why maxmind finds it, yet here it does not. Yet it works on other IP's. Is there some other filtering taking place on this plugin that is excluding the IP in question?

Allow ipv6

I noticed that there is no Ipv6 support.
It's true that there is no city lookup support for ipv6 currently, but country/timezone/continent might still be useful to get.

I've added a pull request: #14

Nothing to publish for tag []

Hey ,
When I tried the following command. There is alway no config file generated.

Laravel version 5.1 :

php artisan vendor:publish
Nothing to publish for tag [].

php artisan vendor:publish --provider=Torann\GeoIP\GeoIPServiceProvider --tag=config
Nothing to publish for tag [config].

php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" --force
Nothing to publish for tag [].

Wrong location

Shortly:
`>>> \GeoIP::getLocation('2.54.143.99');
=> [
"ip" => "127.0.0.0",
"isoCode" => "US",
"country" => "United States",
"city" => "New Haven",
"state" => "CT",
"postal_code" => "06510",
"lat" => 41.31,
"lon" => -72.92,
"timezone" => "America/New_York",
"continent" => "NA",
"default" => true,
]

`
Returns "default" location

While another script (not Laravel)
require "geoip-maxmind/geoipcity.inc.php"; //require "geoip-maxmind/geoipregionvars.php"; $gi = geoip_open("geoip-maxmind/1_GeoLiteCity.dat", GEOIP_STANDARD); $gr = geoip_record_by_addr($gi, $IP); if(!empty($gr->city)) { $gr->country_name = utf8_encode($gr->country_name); $gr->city = utf8_encode($gr->city); echo "{$gr->city}, {$gr->country_name}\n"; } elseif(!empty($gr->country_name)) { $gr->country_name = utf8_encode($gr->country_name); echo "{$gr->country_name}\n"; }
Returns Israel (which is correct).

Call to undefined function Torann\GeoIP\gzopen()

Hi there.
I have this issue on 32-bit Ubuntu 14.04.2 LTS and PHP 5.5.9-1ubuntu4.11 (built: Jul 2 2015 15:17:32) with command php artisan geoip:update

Error Output: PHP Fatal error:  Call to undefined function Torann\GeoIP\gzopen() in vendor/torann/geoip/src/Torann/GeoIP/GeoIPUpdater.php on line 55

When i change gzopen() to gzopen64() it works fine.

Update doesn't work with Paid DB

Running a geoip:update when using the paid update URL doesn't work. It reports the update was successful, but when it first gets accessed, it returns: The MaxMind DB file's search tree is corrupt. I manually downloaded it from the URL, and placed in the correct spot, and all was well. I'm using this url for the update url:

https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-City&date=20160216&suffix=tar.gz&license_key=MYLICENSEKEYHERE

I'm guessing it has something to do with the redirects, but let me know if I can be of more help here.

Anonymous IP returning everything NULL

ran across an IP address which returned no country code neither a default location. After investigation I found out why. On maxmind the IP is down as a anonymous IP address without a geoname_id code. Hence the IP a default location was not returned as the IP was found in the database but with no geo code. Hence everything returned was null instead of default location or an identifier for anonymous IP.

Could you advise on the L4 version what to add to take these anonymous IP's into account instead of returning everything NULL

Double ip address not returning proper location

Hello
After much debug I discovered that my server is returning a double ip address for the remote ip. The remote ip looks like xxx.xxx.xxx.xxx, yyy.yyy.yyy.yyy and the resulting location is returned with default => 1

The double IP is coming from an apache config involving reverse proxy and I have no control over it. Perhaps the package could account for it and just take the first ip?

Making a Peanut Butter & Jelly Sandwich

Just because I am an experienced developer that is now attempting to learn the Laravel coding style... I though I would drop a quick line in regards to the documentation. It probably seems painfully obvious to a lot of people who have been developing with Laravel over the years, however, installing the repo and following the instructions in the readme file was giving me a class not found error. Then I noticed that the error was because Laravel was attempting to look for a GeoIP controller because I had failed to "use GeoIP;" at the top of my controller definition.

So, just for the sake of "idiot-proofing" some things and being clear, might want to explicitly add that to the installation instructions.

Class 'Torann\GeoIP\Client' not found error.

Hi,

Have followed the installation instructions and all works well. It stops working when I change type to web_service in the config file. I'm using the correct user id and license key. I've attached a screenshot of the error I can't understand what I'm doing wrong. Thanks in advance!
torrangeoip

Non-static method Torann\GeoIP\GeoIP::getLocation() should not be called statically, assuming $this from incompatible context

Attempted to use this several different ways. Do I need to sign up for an external account in order to use this? Not very clear from the documentation - not sure if maxmind is optional or required. I also see that another issue was posted with the same error.

Here is my test:

// Routes.php
use Torann\GeoIP\GeoIP;
Route::get('geoip', function() {
    $location = GeoIP::getLocation();
});

Allow caching

Allow caching via the built-in Laravel cache, with options for how long to store.

Support MaxMind country database

It would be great if this extension would support the usage of only the MaxMind country database as well (also for the Laravel 4 version), since the commercial version of it is much cheaper than the city database.

Log files fill up with AddressNotFoundException on private IPv6 addresses

Cross-references: maxmind/GeoIP2-php#74

Error: The address ::1 is not in the database.

I haven't seen any from 127.0.0.1 (IPv4), but GeoIP2 fills up logs very quickly with the above error and stack trace when the error is thrown (discovered by rap2hpoutre/laravel-log-viewer) at https://github.com/maxmind/GeoIP2-php/blob/master/src/Database/Reader.php#L220-L224

Consider adding the following (or a similar implementation) to skip database check if the IP is private:

function is_private_IP($ip) {
    return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE |  FILTER_FLAG_NO_RES_RANGE);
}

Source: https://arjunphp.com/check-if-an-ip-address-is-private-with-php/

IP Mapping updates

Just an inquiry. Once we've downloaded the database from the maxmind. How can we ensure that data in there are up to date? Thanks!

Can you also add on the docs on the workaround on updating the ip mappings also?

Update & Config

Hi,

Just want to let you know I made some composer update these past few days and visibly you updated your package (I checked the commits history).

My app is tied with ~0.2 and after the update it started to stop working...
Undefined index: database_path

I knew it has something to do with the config...
When running php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" it said Publishing Complete! (I had already your config published).

I had to manually delete the config file then re-run php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" to make it works.

Is that normal?

(Very cool the php artisan geoip:update)

GeoLite2-City.mmdb does not

hello ,

i installed this for L4 and followed all steps and download maxmind db into databasa/maxmind/

i dont want use city i need country db so i downloaded country db

but im getting this error

[2014-11-26 16:08:53] production.ERROR: exception 'InvalidArgumentException' with message 'The file "/Applications/XAMPP/xamppfiles/htdocs/laravel/app/database/maxmind/GeoLite2-City.mmdb" does not exist or is not readable.' in /Applications/XAMPP/xamppfiles/htdocs/laravel/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php:45

/Applications/XAMPP/htdocs/laravel/app/database/maxmind$ ls -la
total 4616
drwxr-xr-x 3 appleuser admin 102B Nov 26 05:43 ./
drwxr-xr-x 7 appleuser admin 238B Nov 26 05:44 ../
-rw-r--r-- 1 appleuser admin 2.3M Nov 15 04:39 GeoLite2-Country.mmdb

i
osx 10.9

and when im useing city db i getting this error

[2014-11-26 16:35:06] production.ERROR: exception 'MaxMind\Db\Reader\InvalidDatabaseException' with message 'Error opening database file (/Applications/XAMPP/xamppfiles/htdocs/laravel/app/database/maxmind/GeoLite2-City.mmdb). Is this a valid MaxMind DB file?' in /Applications/XAMPP/xamppfiles/htdocs/laravel/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php:250

error on windows

nvalidDatabaseException in Reader.php line 251:
Error opening database file (C:\laragon\www\web\storage\app/geoip.mmdb). Is

Use Request facade instead of $_SERVER

Hello,
I've noticed that using GeoIP::getLocation() without parameters return the default location if the web server sits behind a proxy.
If I use\GeoIP::getLocation(Request::ip() instead I get the right result. Request is Illuminate\Support\Facades\Request.
I suppose it works fine because internally Request object checks for X-Real-IP X-Forwarded-For and other stuff like this before returning ips.

Regards,
Andrea

When CACHE_DRIVER=file => "This cache store does not support tagging"

Hi,

When "CACHE_DRIVER=file" is receive this error:
BadMethodCallException in Repository.php line 391: This cache store does not support tagging. in Repository.php line 391 at Repository->tags(array('torann-geoip-location')) in CacheManager.php line 301 at CacheManager->__call('tags', array(array('torann-geoip-location'))) in Cache.php line 32 at Cache->__construct(object(CacheManager), array('torann-geoip-location'), '30') in GeoIP.php line 91

Unfortunatly, I must configure my cache this way to make it work:
CACHE_DRIVER=array

FYI, I'm upgrading from 0.2 to 1.0. Was working with "CACHE_DRIVER=file"

Any ideas?

Config to set the default location

It would be nice if we could have config option to specify the default location that it falls-back to.
Otherwise something to indicate that the location couldn't be determined, would do fine as well, like:

array (
    "ip"           => "127.0.0.0",
    "isoCode"      => "",
    "country"      => "",
    "city"         => "",
    "state"        => "",
    "postal_code"  => "",
    "lat"          => null,
    "lon"          => null
);

Class not found

I use Laravel 5.1

and here is my providers :
Torann\GeoIP\GeoIPServiceProvider::class,
alias:
'GeoIP' => Torann\GeoIP\GeoIPFacade::class,

FatalErrorException in ProviderRepository.php line 146:
Class 'Torann\GeoIP\GeoIPServiceProvider' not found

Laravel 5.3 issue?

Hello,

I am getting the following:

php artisan geoip:update
The current service "Illuminate\Foundation\Application" does not support updating.

Also, whenever I use the geoip helper I am getting:

geoip('192.168.0.1');

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Foundation\Application::hydrate()

Any idea?

Check ip logic is returning false

CheckIp function is returning false in case ip = 1.39.45.208

And which shouldn't happen. Tell me how to fix this.

 private function checkIp($ip)
{
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
        $longip = ip2long($ip);

        if (! empty($ip)) {
            foreach ($this->reserved_ips as $r) {
                $min = ip2long($r[0]);
                $max = ip2long($r[1]);
                if ($longip >= $min && $longip <= $max) {
                    return false;
                }
            }

            return true;
        }
    } else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
        return true;
    }

Error when moving to production

Hi!

Everything works localy, but when moving to production I get this error when trying to get the IP's location:
The file "/var/www/laravel/app/database/maxmind/GeoLite2-City.mmdb" does not exist or is not readable.

I'm calling it like this:
$location = GeoIP::getLocation();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.