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

Last update: Aug 4, 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
Determine the geographical location of website visitors based on their IP addresses.

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

Aug 4, 2022
This is a Location Registration For location registration

location-registration-system This is a Location Registration location-registration-system for users registration location if your location verifide Wi

Feb 10, 2022
Server manager is a open source project made for people so that they can add the servers to one single place irrespective of their provider and manage it through one location.
Server manager is a open source project made for people so that they can add the servers to one single place irrespective of their provider and manage it through one location.

Server Manager Are you sick of having to log into hundreads of different website just to access your server? Well we got you, Server manager is a open

Jan 18, 2022
laravel package help you to implement geographical calculation, with several algorithms that help you deal with coordinates and distances.
laravel package help you to implement geographical calculation, with several algorithms that help you deal with coordinates and distances.

Geographical Calculator Geographical Calculator was developed for laravel 5.8+ to help you to implement geographical calculation, with With several al

Jul 24, 2022
CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due

PHP Cron Expression Parser NOTE This fork has been deprecated and development moved to https://github.com/dragonmantank/cron-expression. More informat

Aug 15, 2022
Analyze content to determine the appropriate Internet media type

Canal Content analysis for the purpose of determining Internet media types. Requirements PHP 5.3+ Installation Through Composer as dflydev/canal. Usag

Feb 11, 2022
CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due

The PHP cron expression parser can parse a CRON expression, determine if it is due to run, calculate the next run date of the expression, and calculate the previous run date of the expression. You can calculate dates far into the future or past by skipping n number of matching dates.

Aug 14, 2022
Divide / Split your WordPress Blog visitors into 4 links by using Re-skinning URL splitter
Divide / Split your WordPress Blog visitors into 4 links by using Re-skinning URL splitter

Re-skinning URL splitter Tool Divide / Split your Wordpress Blog visitors into 4 links by using Re-skinning URL splitter Re-skinning URL Splitter Feat

Mar 16, 2022
A WordPress plugin that displays proxied war news from the free world to Russian IP address visitors with option to block further access.
A WordPress plugin that displays proxied war news from the free world to Russian IP address visitors with option to block further access.

A WordPress plugin that displays proxied war news from the free world to Russian IP address visitors with option to block further access.

Jul 15, 2022
A PHP library to deal with all those media services around, parsing their URLs and displaying their audios/videos.

MediaEmbed A utility library that generates HTML embed tags for audio or video located on a given URL. It also parses and validates given media URLs.

Jul 16, 2022
Small PHP library to valid email addresses using a number of methods.

Email Validator Small PHP library to valid email addresses using a number of methods. Features Validates email address Checks for example domains (e.g

Jul 3, 2022
A library for IP addresses calculations

PHP IP tools This library provides tooling for IP address calculations based on rlanvin/php-ip Free IP blocks calculation Compute the best possible al

Mar 25, 2022
Laravel 8 Project Restrict User Access From IP Addresses. prevent other ip address that want to access over secure api or urls.

block-ip-address-laravel Laravel 8 Project Restrict User Access From IP Addresses. prevent other ip address that want to access over secure api or url

Mar 24, 2022
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

Aug 7, 2022
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.

IP is an immutable value object for (both version 4 and 6) IP addresses. Several helper methods are provided for ranges, broadcast and network address

Aug 5, 2022
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

Aug 15, 2022
A simple way to deploy your application to a remote location.

Deploy Plugin A simple way to deploy your application to a remote location. Currently in Active Development This plugin is incomplete. This plugin is

Apr 30, 2022
get nearby location by coordinate from eloquent laravel

LARAVEL-COORDINATE get nearby location data from database with eloquent laravel Installation composer require bagusindrayana/laravel-coordinate In M

Jul 9, 2022
PHP library for determining the physical location of binaries

Bin Locator Library for searching binary files in the operating system. Requirements PHP >= 7.4 Installation Library is available as composer reposito

Jul 27, 2022