A library that assists in retrieving the continent and country information from Cloudflare's request headers.
You can install this library with Composer:
$ composer require nathandentzau/cloudflare-geolocation
- PHP 7.2+
- Symfony HTTP Foundation component.
<?php
use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation;
use Symfony\Component\HttpFoundation\Request;
$request = Request::create();
$geolocation = new CloudflareGeolocation($request);
/** @var \NathanDentzau\CloudflareGeolocation\Continent */
$continent = $geolocation->getCurrentContinent();
<?php
use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation;
use Symfony\Component\HttpFoundation\Request;
$request = Request::create();
$geolocation = new CloudflareGeolocation($request);
/** @var \NathanDentzau\CloudflareGeolocation\Country */
$country = $geolocation->getCurrentCountry();
<?php
use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation;
use Symfony\Component\HttpFoundation\Request;
$request = Request::create();
$geolocation = new CloudflareGeolocation($request);
$ipAddress = $geolocation->getConnectingIp();
This project is licensed under the MIT License.