PHP code example of middlewares / geolocation

1. Go to this page and download the library: Download middlewares/geolocation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

middlewares / geolocation example snippets


$freeGeoIpProvider = new Geocoder\Provider\FreeGeoIp($adapter);

$dispatcher = new Dispatcher([
    new Middlewares\Geolocation($freeGeoIpProvider),

    function ($request) {
        //Get the client location
        $location = $request->getAttribute('client-location');

        $country = $location->first()->getCountry();
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());