Download the PHP package hibit-dev/geodetect without Composer

On this page you can find all versions of the php package hibit-dev/geodetect. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package geodetect

Automatically detect user's geo data based on their IP address

GitHub Actions Workflow Status GitHub License Packagist Version Packagist Downloads Tests Coverage

GeoDetect: IP-based country detection

GeoDetect is a framework-agnostic PHP package that allows to effortlessly extract valuable country information from IP addresses. Powered by a robust and up-to-date IP geolocation database, the package provides accurate results and ensures reliable performance. By Integrating GeoDetect into your PHP applications developers can easily implement geolocation functionality without the hassle of building and maintaining their own IP geolocation database.

Installation

Install GeoDetect using composer require:

Usage

Once installed, include the GeoDetect package in your class:

Instantiate the class or use the dependency injection:

Retrieve country record providing user's IP address:

Finally, use available helpers to retrieve the required country information:

Self-hosted database

The package utilizes MaxMind's database in the background, which is regularly updated to ensure the accuracy of the data. However, you also have the option to use a self-hosted database by specifying the location of the DB file:

The package includes MaxMind's database of 2024-04-12

Printing user flag

The GeoDetect package offers the capability to easily display a user's flag. Simply create an image HTML tag and insert the corresponding source for the image based on the country's ISO2 code:

By default, the resulting flag will have a height of 20px and a width that typically varies around 30px.

Sizes can be adjusted and even replaced with an SVG image if needed. To alter the format, the getFlagByIsoCode method requires a second parameter to be provided:

Note: FR was used for illustrative purposes; obtain the country code through the getIsoCode method of the country record. Alternatively, use the 2-character ISO code of the country if it's already available from another source.

Implementation in Laravel

To facilitate testing, we will create a new route within our Laravel application. In the routes/web.php file, a new route called get-country has been added. When this route is accessed, it will return all the available information in JSON format.

Please note that when testing the country detection functionality locally, it may not work as expected. This is because the client IP address in the request instance is typically set to localhost (127.0.0.1). Keep this in mind while testing the country detection feature on your local development environment.

Country names translation

The package comes with configured discovery option to enable Laravel to automatically identify and publish the necessary translations. You can find the translations in the /lang/en/geodetect.php file, and feel free to make any modifications to the translations as needed. If the files are not present, please manually publish them by executing the following command:

Once the translations have been published, you can use them to display the country name in any blade file using the translation directive:

Alternatively, the following syntax can be used outside the blades:

Documentation

Instructions and full documentation are always available on HiBit.
Additional information about this repository can be found here:

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

About HiBit

HiBit isn't just a blog; it's your go-to space for everything related to development, IT, and the wonders of electronics. Designed for developers, IT enthusiasts, and electronics hobby lovers, HiBit is a dynamic hub that keeps you in the loop with fresh and engaging content.

Explore a collection of articles, tutorials, and insights, encouraging a lively community where reading, commenting, discussing, and sharing experiences is not just promoted but celebrated.

License

The MIT License (MIT). Please see License File for more information.


All versions of geodetect with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
geoip2/geoip2 Version ^3.0
illuminate/support Version ^8.0|^9.0|^10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hibit-dev/geodetect contains the following files

Loading the files please wait ....