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

Last update: Jun 24, 2022

GeoIP for Laravel

Build Status Latest Stable Version Total Downloads Patreon donate button Donate weekly to this project using Gratipay Donate to this project using Flattr Donate to this project using Paypal

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

Official Documentation

Documentation for the package can be found on Lyften.com.

Older versions of Laravel

Contributions

Many people have contributed to project since its inception.

Thanks to:

GitHub

https://github.com/Torann/laravel-geoip
Comments
  • 1. 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?

    Reviewed by paceband at 2016-10-22 03:00
  • 2. Class 'Torann\GeoIP\GeoIPFacade' not found

    Not sure what I'm doing wrong here...

    Specs:

    • Laravel 5.4
    • Mac
    • "torann/geoip": "^1.0"
    • "geoip2/geoip2": "^2.4"

    Any ideas...

    app.php

       'providers' => [
    ...
            Torann\GeoIP\GeoIPServiceProvider::class,
    ...
    
        'aliases' => [
    ...
            'GeoIP' => Torann\GeoIP\GeoIPFacade::class,
    ...
    

    PagesController.php

    ...
    use Torann\GeoIP\GeoIPFacade as GeoIP; // I've tried this,
    use GeoIP as GeoIP;                    // this,
    use GeoIP;                             // and this...
    ...
    
    public function getHome()
        {
            ...
            $data['visits'] = Redis::incr('visits');
            $data['$location'] = GeoIP::getLocation();
            return View::make('pages.home', $data);
            ...
        }
    

    home.blade.php

    ...
    <!-- USER :: DATA -->
    <!-- Visit #{{ $visits }} -->
    <!-- {{ $location }} -->
    ...
    

    Error: Class 'Torann\GeoIP\GeoIPFacade' not found

    /Users/user/Sites/sogenius/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php
            if (static::$facadeNamespace && strpos($alias, static::$facadeNamespace) === 0) {
                $this->loadFacade($alias);
     
                return true;
            }
     
            if (isset($this->aliases[$alias])) {
                return class_alias($this->aliases[$alias], $alias);
            }
        }
    
    Reviewed by sogeniusio at 2017-04-19 04:23
  • 3. The GeoIP service is not valid.

    Hi all, I am using laravel 5.5. I have config on app.config for Provider and Aliases. When i call: $location = GeoIP::getLocation(); --> Bug: THe GeoIP service is not valid. (In GeoIP.php line 205)

    Help me!

    Reviewed by hitechqb at 2018-01-02 08:26
  • 4. 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();
    });
    
    Reviewed by opheliadesign at 2015-02-20 20:23
  • 5. 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?

    Reviewed by rickshawhobo at 2015-04-10 14:57
  • 6. Support for Laravel 7

    Also some opinionated removal of PHP 7.1 and Laravel 5.5 support. The current version that supports Laravel 5.5 is stable and working, so let's move forward.

    Reviewed by mikemand at 2020-02-29 22:39
  • 7. Undefined method reference...

    Hi,

    I would just like to point out a reference to a method that does not (or no longer) exists..

    https://github.com/Torann/laravel-geoip/blob/d00e9b5b9c8e9c79c47fc4d78d4b47db1cd532c3/src/GeoIP.php#L164

    image

    Possible fix: https://github.com/Seldaek/monolog/commit/d686f25f6c1ce9706e23cf1c6f97c76e8bf83d09

    Reviewed by PhoenixPeca at 2019-09-06 15:34
  • 8. Allow dependency injection

    Allow dependency injection. To avoid using a global variable.

        use Torann\GeoIP\GeoIP;
    
        public function login(GeoIP $geoip)
        {
            return $geoip->getLocation($request->ip())->toArray();
        }
    
    Reviewed by KaliaJS at 2021-03-23 14:23
  • 9. Fix MaxMind database fetching

    This is a follow-up to #163 that is intended to fix #162.

    It expands on the work by @tylermann - with a couple of differences.

    Instead of adding the database filename to the config it searches for the first file with the extension .mmdb and assumes this is the correct one. Seems like a little simpler to me though less configurable - open to feedback here.

    It would be great if we could leverage Laravel's filesystem adapter as it would clean up much of the directory creation/removal code, but that's probably part of a larger discussion.

    Reviewed by dwightwatson at 2020-01-02 01:32
  • 10. 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?

    Reviewed by mendrinos at 2016-10-10 13:48
  • 11. 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.

    Reviewed by tholu at 2015-02-20 09:49
  • 12. fix: temporary fix openssl issue on some machine

    Hello,

    Php currently have an issue with openssl https://github.com/php/php-src/issues/8369,

    For some machine, file_get_contents and file_put_contents will fail, we could fix it with this approach https://github.com/guzzle/psr7/issues/504#issuecomment-1114693965, but I think it overkill for a simple database update command.

    I'll revert this commit sometime in the future when php got fix.

    Reviewed by kocoten1992 at 2022-05-05 08:01
  • 13. Error: Declaration of Torann\GeoIP\Location::offsetExists(Torann\GeoIP\mixed $offset): bool must be compatible with ArrayAccess::offsetExists($offset)

    Trying to get this working:

    • Laravel 8.0 on PHP 7.3.16-fpm
    • Installed laravel-geoip with Composer
    • Cache Driver to Array
    • Installed geoip2 with Composer
    • Set /config/geoip.php 'service' to use 'maxmind_database'
    • Created Maxmin account and added Maxmind credentials to .env
    // Running this
    $location = \GeoIP::getLocation(\Request::ip());
    
    // Gives me:
    Declaration of Torann\GeoIP\Location::offsetExists(Torann\GeoIP\mixed $offset): bool must be compatible with ArrayAccess::offsetExists($offset)
    
    Reviewed by netm at 2022-04-12 22:05
  • 14. geoip:update with maxmind_database uses too much memory

    I get:

    PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /var/app/current/vendor/torann/geoip/src/Services/MaxMindDatabase.php on line 78
    PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 131072 bytes) in /var/app/current/vendor/sentry/sentry/src/HttpClient/Plugin/GzipEncoderPlugin.php on line 53
    

    Perhaps we could use https://github.com/splitbrain/php-archive to reduce memory use?

    Reviewed by jordanade at 2022-03-09 23:52
  • 15. DB-IP: free database

    This is for everyone looking for a completely free database (as far as i can see also for commercial use) https://db-ip.com/db/download/ip-to-city-lite Needs to be said: The city accuracy is not that good

    Here is the corresponding service:

    <?php
    
    namespace App\Services\GeoIP;
    
    use PharData;
    use Exception;
    use GeoIp2\Database\Reader;
    use Torann\GeoIP\Services\MaxMindDatabase;
    
    class DBIP extends MaxMindDatabase
    {
        /**
         * Update function for service.
         *
         * @return string
         * @throws Exception
         */
        public function update()
        {
            if ($this->config('database_path', false) === false) {
                throw new Exception('Database path not set in config file.');
            }
    
            $this->withTemporaryDirectory(function ($directory) {
                $gzFile = sprintf('%s/dbip-city-lite.gz', $directory);
    
                file_put_contents($gzFile, fopen($this->config('update_url'), 'r'));
    
                $file = gzopen($gzFile, 'rb');
                $outFile = fopen($this->config('database_path'), 'wb');
                while (!gzeof($file)) fwrite($outFile, gzread($file, 4096));
    
                fclose($outFile);
                gzclose($file);
            });
    
            return "Database file ({$this->config('database_path')}) updated.";
        }
    }
    

    and the config:

        'services' => [
    
            'db_ip' => [
                'class' => \App\Services\GeoIP\DBIP::class,
                'database_path' => storage_path('app/geoip.mmdb'),
                'update_url' => sprintf("https://download.db-ip.com/free/dbip-city-lite-%s-%s.mmdb.gz", date('Y'), date('m')),
                'locales' => ['en'],
            ],
    
            // ...
        ],
    
    Reviewed by Artem-Schander at 2022-01-27 16:59
  • 16. Error installing in L7+PHP8

    I'm struggling to use laravel-geoip in a new laravel 7 instalation. Even if it's the first package I install I keep getting this error.

    composer output:

      Problem 1
        - torann/geoip 3.0.1 requires php ^7.2 -> your php version (8.0.12) does not satisfy that requirement.
        - torann/geoip 3.0.2 requires illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
        - Root composer.json requires torann/geoip ^3.0 -> satisfiable by torann/geoip[3.0.1, 3.0.2].
    
    You can also try re-running composer require with an explicit version constraint, e.g. "composer require torann/geoip:*" to figure out if any version is installable, or "composer require torann/geoip:^2.1" if you know which you need.
    

    Thanks in advance

    Reviewed by jfernandes-dtm at 2021-11-29 11:12
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Jun 28, 2022
A Laravel (php) package to interface with the geo-location services at geonames.org.

geonames v7.x A Laravel (php) package to interface with the geo-location services at geonames.org. Major Version Jump I jumped several major versions

Jul 2, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Jun 26, 2022
This package gives Eloquent models the ability to manage their friendships.

Laravel 5 Friendships This package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

Jun 22, 2022
Madison is a platform for lawmakers to share legislation with their citizens, allowing the community to add comments and suggest improvements.

Madison Madison is an open-source document engagement and feedback platform. While Madison can be used to collaborate on many different kinds of docum

Jun 17, 2022
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.

What is GitScrum? GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivit

Jun 28, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Jun 24, 2022
Log executed Laravel SQL queries and their line number and more

A lightweight laravel package for logging executed SQL queries, line number and more

Jun 2, 2022
Rebuild the todo website with Laravel and Vue
Rebuild the todo website with Laravel and Vue

Lara-Todo This is a course that I took at Udmey, to create a todo website with Laravel and Vue.js Start First we need to download and setup Composer.

Dec 1, 2021
PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

reCAPTCHA PHP client library reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the s

Jun 28, 2022
Laravel package that converts your application into a static HTML website
Laravel package that converts your application into a static HTML website

phpReel Static Laravel Package phpReel Static is a simple Laravel Package created and used by phpReel that converts your Laravel application to a stat

Jan 17, 2022
this package makes laravel website a progressive web application.
this package makes laravel website a progressive web application.

Laravel PWA You can follow this video tutorial as well for installation. Installation Install the package by the following command, composer require l

Jun 13, 2022
A simple website to inform you where to watch anime legally in Indonesia.

WibuSaka A simple app to inform you where to watch anime legally in Indonesia. WibuSaka uses Jikan.moe API to fetch anime datas. Requirements PHP 7.4+

May 24, 2022
A blog website with blog details with laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Mar 6, 2022
This Laravel 8 package makes it possible for you to set your website in "Under Construction" mode.
This Laravel 8 package makes it possible for you to set your website in

Laravel Under Construction This Laravel package makes it possible to set your website in "Under Construction" mode. Only users with the correct 4 digi

Jun 16, 2022
Modeling online shopping website with PHP/Laravel
Modeling online shopping website with PHP/Laravel

Online Shop M-54 Bootcamp final project. Modeling digikala website with PHP/Laravel. Creating a simple WooComers website with Laravel and Blade. Tools

Jan 2, 2022
PlayZ is an esport event organization and management website allowing the creation of tournaments on the most popular video games of the esport scene.

PlayZ the playz to play Table of Contents Description "What is Playz?" In one sentence PlayZ is "an esport event organization and management website a

Dec 7, 2021
Source code for the filamentadmin.com website.
Source code for the filamentadmin.com website.

Filament Demo App A demo application to illustrate how Filament Admin works. Installation Clone the repo locally: https://github.com/laravel-filament/

Jul 1, 2022
Suankularb Computer Club (SKCC29) SKOI Competition Register Website
Suankularb Computer Club (SKCC29) SKOI Competition Register Website

Suankularb Computer Club (SKCC29) SKOI Competition Register Website (Thank to all SKCC29 members for art work and all help) (This work is created before I using git version control system)

Dec 26, 2021